-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlooplist.py
More file actions
55 lines (43 loc) · 997 Bytes
/
Copy pathlooplist.py
File metadata and controls
55 lines (43 loc) · 997 Bytes
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
# loop in list
# to show all item in list one by one.
a=["sorry","vikrant","welcome","ankur","world", "welcome"]
for x in a:
print(x)
# full list shown with same number of item's in it.
for i in range(len(a)):
print(a)
# with while loop.
i=0
while i < len(a):
print(a[i])
i=i+1
# another way to use for loop.
[print(x) for x in a]
print('\n\n')
# for adding a unique type of item form on list to another.
# we added the items that contain letter "o" in it.
b=["ANKUR"]
for y in a:
if "o" in y:
b.append(x)
print(b)
# another way to a unique item in new list.
c=[x for x in a if "e" in x]
print(c)
# removing an item from form a list.
d=[x for x in a if x != "ankur"]
print(d)
# loop in list
e=[x for x in range(14)]
print(e)
# condition in
f=[x for x in range(50) if x < 39]
print(f)
g=[x for x in range(50) if x < 50/2]
print(g)
# change output
h=["ok" for x in a]
print(h)
# cahnge all items in list of same value
i=[x if x!="welcome" else "DONE" for x in a]
print(i)