Skip to content

Commit 26596e2

Browse files
committed
example4
1 parent 44edb1f commit 26596e2

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

example4.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
'''
3+
write a program to get a list with the numbers of every word or items.
4+
5+
'''
6+
7+
names = ['alex', 'anna', 'Lokus', 'phillips']
8+
9+
# 1 ---> [4, 4, 5, 8]
10+
11+
result = []
12+
for n in names:
13+
result.append(len(n))
14+
15+
print(result)
16+
17+
18+
print('--------------------------------')
19+
20+
'''
21+
22+
write a program to get a list with the names, who has more than 3 letters.
23+
24+
25+
'''
26+
27+
#2 ---> names letter > 3
28+
29+
result = []
30+
for n in names:
31+
if len(n) > 4:
32+
result.append(n) #if we want to get the length we write .append(len(n))
33+
34+
35+
print(result)
36+
37+
38+
39+
print('--------------------------------')
40+
41+
42+
'''
43+
44+
Write a program to add new item in a list, with
45+
sorting according to the number of the letter.
46+
47+
'''
48+
49+
def my_insert(names, new):
50+
for n in names:
51+
if len(new) < len(n):
52+
index = names.index(n)
53+
names.insert(index, new)
54+
break
55+
print(names)
56+
57+
names = ['alex', 'anna', 'Lokus', 'phillips']
58+
my_insert(names, 'tt')
59+
60+
'''
61+
write a program to print a list inside a list.
62+
63+
'''
64+
65+
l =['alex', 'anna', [1, 2, 3, 4], 'Lokus']
66+
67+
for i in l:
68+
if type(i) == list:
69+
for n in i:
70+
print(n)
71+
else:
72+
print(i)

0 commit comments

Comments
 (0)