-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample4.py
More file actions
72 lines (43 loc) · 1.11 KB
/
example4.py
File metadata and controls
72 lines (43 loc) · 1.11 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'''
write a program to get a list with the numbers of every word or items.
'''
names = ['alex', 'anna', 'Lokus', 'phillips']
# 1 ---> [4, 4, 5, 8]
result = []
for n in names:
result.append(len(n))
print(result)
print('--------------------------------')
'''
write a program to get a list with the names, who has more than 3 letters.
'''
#2 ---> names letter > 3
result = []
for n in names:
if len(n) > 4:
result.append(n) #if we want to get the length we write .append(len(n))
print(result)
print('--------------------------------')
'''
Write a program to add new item in a list, with
sorting according to the number of the letter.
'''
def my_insert(names, new):
for n in names:
if len(new) < len(n):
index = names.index(n)
names.insert(index, new)
break
print(names)
names = ['alex', 'anna', 'Lokus', 'phillips']
my_insert(names, 'tt')
'''
write a program to print a list inside a list.
'''
l =['alex', 'anna', [1, 2, 3, 4], 'Lokus']
for i in l:
if type(i) == list:
for n in i:
print(n)
else:
print(i)