-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMy Ongoing Python Programming Experiments.py
More file actions
110 lines (74 loc) · 3.05 KB
/
My Ongoing Python Programming Experiments.py
File metadata and controls
110 lines (74 loc) · 3.05 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# My Ongoing Python Programming Experiments
# You can do a lot with for loops. I practice Python everyday and I'm
# always tripping onto things, just by trial and error alone. I wasn't
# shown this at all. This is one of my own happy accidents. I got really
# bored and did this for us all.
names1 = ['Bob','Rob','dog','cat']
names2 = ['John','Tom','bird','fish']
names3 = ['Terry','Mary','turtle','monkey']
for i,x,y,z in names1,names2,names3:
print('Hello',i+'. How are you? You bought a cute',y,'I see...')
print('Hello',x+'. How are you? You bought a cute',z,'I see...')
''''''''''''''''''''''''''''''''''''''''''''''''''''''
names1 = ['Bob','Rob','dog','cat']
names2 = ['John','Tom','bird','fish']
names3 = ['Terry','Mary','turtle','monkey']
sentence= 'Hello','. How are you? You bought a cute','I see...'
for i,x,y,z in names1,names2,names3:
print(sentence[0],i+sentence[1],y,sentence[2])
print(sentence[0],x+sentence[1],z,sentence[2])
''''''''''''''''''''''''''''''''''''''''''''''''''''''
names1 = ['Bob','Rob','dog','cat']
names2 = ['John','Tom','bird','fish']
names3 = ['Terry','Mary','turtle','monkey']
sentence = 'Hello','. How are you? You bought a cute','I see...'
for i,x,y,z in names1,names2,names3:
print('{} {} {} {}'.format(sentence[0],i+sentence[1],y,sentence[2])) # The old formated example:
print('{} {} {} {}'.format(sentence[0],x+sentence[1],z,sentence[2]))
''''''''''''''''''''''''''''''''''''''''''''''''''''''
names1 = ['Bob','Rob','dog','cat']
names2 = ['John','Tom','bird','fish']
names3 = ['Terry','Mary','turtle','monkey']
sentence = 'Hello','. How are you? You bought a cute','I see...'
for i,x,y,z in names1,names2,names3:
print(f'{sentence[0]} {i}{sentence[1]} {y} {sentence[2]}') # The new f' formated example:
print(f'{sentence[0]} {x}{sentence[1]} {z} {sentence[2]}')
''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's play with the zip function()
list1 = ['zip 1','zip 2','zip 3','zip 4']
list2 = ['zip 5','zip 6','zip 7','zip 8']
zip_list = zip(list1,list2)
for i in zip_list:
print(i)
# or this:
list1 = ['zip 1','zip 2','zip 3','zip 4']
list2 = ['zip 5','zip 6','zip 7','zip 8']
zip_list = zip(list1,list2)
for i in zip_list:
print(i[0])
# or this:
list1 = ['zip 1','zip 2','zip 3','zip 4']
list2 = ['zip 5','zip 6','zip 7','zip 8']
zip_list = zip(list1,list2)
for i in zip_list:
print(i[1])
# or this:
list1 = ['zip 1','zip 2','zip 3','zip 4']
list2 = ['zip 5','zip 6','zip 7','zip 8']
zip_list = zip(list1,list2)
for i in zip_list:
print(i[0])
print(i[1])
''''''''''''''''''''''''''''''''''''''''''''''''''''''
# Let's play with the enumerate function()
list1 = ['enumerate 1','enumerate 2','enumerate 3','enumerate 4']
list2 = ['enumerate 5','enumerate 6','enumerate 7','enumerate 8']
x,y = enumerate(list1),enumerate(list2)
print(tuple(x))
print(list(y))
# or this:
list1 = ['enumerate 1','enumerate 2','enumerate 3','enumerate 4']
list2 = ['enumerate 5','enumerate 6','enumerate 7','enumerate 8']
x,y = enumerate(list1),enumerate(list2)
print(dict(x))
print(set(y))