-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab4.py
50 lines (34 loc) · 1.3 KB
/
lab4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# LAB 4: Lists in Python
# 1. Create a list of characters from a string which is stored in variable.
# 2. Create list of words stored in the following variable.
# s = "Earth is Round"
# 3. Find the length of list by using len() function.
# list_1 = ['a', ['bb', ['ccc', 'ddd'], 'ee', 'ff'], 'g',
# ['hh', 'ii'], 'j']
# 4. From the above list_1 remove the second item in list.
# 5. Add "hh" to the end of list_1 and store in list_3. Also print list_3.
# 6. Remove 'a' from list_1 and print the result
# 1. Create a list of characters from a string which is stored in variable.
str= 'Hello World'
list_of_char=list(str)
print(list_of_char)
# 2. Create list of words stored in the following variable.
# s = "Earth is Round"
s = "Earth is Round"
list_of_words=s.split()
print(list_of_words)
# 3. Find the length of list by using len() function.
# list_1 = ['a', ['bb', ['ccc', 'ddd'], 'ee', 'ff'], 'g',
# ['hh', 'ii'], 'j']
list_1 = ['a', ['bb', ['ccc', 'ddd'], 'ee', 'ff'], 'g', ['hh', 'ii'], 'j']
print(len(list_1)) #returns 5
# 4. From the above list_1 remove the second item in list.
del(list_1[1])
print(list_1)
# 5. Add "hh" to the end of list_1 and store in list_3. Also print list_3.
list_1.append('hh')
list_3=list_1
print(list_3)
# 6. Remove 'a' from list_1 and print the result
list_1.remove('a')
print(list_1)