-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
217 lines (176 loc) · 5.39 KB
/
main.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# height = [1.80, 1.75, 1.70, 1.65, 1.60]
# weight = [80, 70, 65, 55, 50]
# x = [1, 2, 3, 4, 5]
# print(all(x))
# print(any(x))
# print(dir())
# print(divmod(10,3))
# first = [11.25, 18.0, 20.0]
# second = [10.75, 9.50]
# first.append(100)
# first.remove(18.0)
# print(first)
# first.reverse()
# print(first)
myString = 'hello i am ahmed'
print(myString.title())
print(myString.capitalize())
x,y,z = '1','11','111'
print(x.zfill(4))
print(y.zfill(4))
print(z.zfill(4))
print(myString.upper())
print(myString.count('e'))
str = "ILovePython25"
print(str.isalnum())
money = 500165968123
print("Money in the bank: {:,.2f}".format(money))
myList = [1,2,8,9,5,6,3]
print(myList)
a =myList
a.append(150)
print(myList)
a.pop()
print(myList)
a.pop()
print(myList)
print('*'*30)
ls = [50,60,70]
m,n,o = ls
print(m)
print(n)
print(o)
print('*'*30)
mySet = {2,4,2,8,6,5,4,8,9,10}
print(len(mySet)) #7
mySet.add(7)
print(mySet)
#mySet.remove(80) #error because 80 not in the set
print(mySet)
mySet.discard(80) #looks like remove but no error
print(mySet)
mySet2 = {'A','B','C','D'}
mySet.update(mySet2) # update = union -> looks like add but add multiple values
print(mySet)
mySet.union(mySet2)
print(mySet)
##############################################################
set1 = {1,2,3,4,5,"Ahmed",'X',True}
set2 = {'X',1,2,False,'Omar'}
# difference() (set1 - set2) -> return a set that contains the difference between two sets
print(set1.difference(set2)) # {3, 4, 5, 'Ahmed'}
#difference_update() (set1 - set2) -> remove the items that exist in both sets (update the original set)
# set1.difference_update(set2)
# print(set1) # {3, 4, 5, 'Ahmed'}
#intersection() (set1 & set2) -> return a set that contains the intersection between two sets
print(set1.intersection(set2)) # {1, 2, 'X'}
#intersection_update() (set1 & set2) -> update the original set with the intersection between two sets
# set1.intersection_update(set2)
# print(set1) # {1, 2, 'X'}
#semmetric_difference() (set1 ^ set2) -> return a set that contains the symmetric difference between two sets (items that exist in one set but not in both)
print(set1.symmetric_difference(set2)) # {3, 4, 5, 'Ahmed', False, 'Omar'}
#symmetric_difference_update() (set1 ^ set2) -> update the original set with the symmetric difference between two sets
# set1.symmetric_difference_update(set2)
# print(set1) # {3, 4, 5, 'Ahmed', False, 'Omar'}
#union() (set1 | set2) -> return a set that contains the union between two sets
print(set1.union(set2)) # {1, 2, 3, 4, 5, 'Ahmed', 'Omar', 'X', False}
print('=' * 30)
print('yes') if 10 > 5 else print('no')
print("Hi" if 10 < 5 else "Bye")
print('=' * 30)
mySkills = {
"Html":"90%",
"PHP":"80%",
"JS":"70%",
"Css":"60%",
"Python":"75%",
}
for skill in mySkills:
print(f"my progress in Lang {skill} is: {mySkills[skill]}")
print('='*30)
for key,value in mySkills.items():
print(f"{key} => {value}")
print('='*30)
peoples = {
"Ahmed" :{
"html":"80%",
"css":"90%",
"js":"70%",
"php":"60%",
},
"Omar" :{
"html":"60%",
"css":"70%",
"js":"90%",
"php":"80%",
},
"Ali" :{
"html":"70%",
"css":"60%",
"js":"80%",
"php":"90%",
}
}
for name in peoples:
print(name)
for skill in peoples[name]:
print(skill, " -> ",peoples[name][skill])
print('='*30)
for pepoles_Key, peoples_value in peoples.items():
print(f"{pepoles_Key} progress is: ")
for lang_key, lang_value in peoples_value.items():
print(f"{lang_key} => {lang_value}")
print('='*30)
def show_datails(* skills):
print("Your Skills are : ")
for skill in skills:
print(skill)
show_datails("Html","js","algorithms")
print('*'*30)
# Recursion
def cleanWord(word): #AAhmmmeeeddd
if len(word) == 1:
return word
if word[0] == word[1]:
return cleanWord(word[1:])
return word[0] + cleanWord(word[1:])
print(cleanWord("AAhmmmeeeddd"))
####################################################
### lambda Function = Anonymous function
### lambda type is function
### Syntax -> [Keyword lambda] [variables_names] [:] [block of code]
hi = lambda name : f"Hi {name}"
print(hi("Ahmed"))
print(type(hi))
print('*'*30)
#-----------------------------
#----- Iterable vs Iterator
#-----------------------------
# Iterable -> is an object that contains a collection of items (list, tuple, set, dictionary, String)
# Iterator -> is an object that represent a stream of data
# iterator -> object used to iterate over iterable objects like lists, tuples, sets, and dictionaries using the iter() and next() functions
# iter() -> return an iterator object
# next() -> return the next item in the iterable object
# StopIteration -> raised when the next() function reaches the end of the iterable object
# you can generate an iterator from an iterable object using the iter() function
myList = [1,2,3,4,5]
myIter = iter(myList)
print(next(myIter)) #1
print(next(myIter)) #2
print('*'*30)
#------------------- For loop generate an iterator automatically -------------------
for letter in "Ahmed":
print(letter)
print('*'*30)
for letter in iter("Ahmed"):
print(letter)
#------------------------------------------------------------------------------------
print('*'*30)
frozenSet = frozenset('aabbss')
print(type(frozenSet))
def Fun():
''' this is the describtion of the function'''
pass
print(Fun.__doc__)
help(Fun)
print('*'*30)