-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfichier.py
More file actions
134 lines (112 loc) · 2.97 KB
/
Copy pathfichier.py
File metadata and controls
134 lines (112 loc) · 2.97 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from math import *
from random import *
from builtins import int
from decorator import *
from itertools import permutations,count,takewhile,accumulate,product
from re import *
import re
ages={"dave":24,"Mary":42,"john":58} #dictionaries
print(ages["dave"])
primary={"red":[255,0,0],"blue":[0,255,0],"green":[0,0,255]}
print(primary["red"])
nums={1:"one",2:"two",3:"three"}
print(1 in nums,"three"in nums, 4 not in nums)
pairs={1:"apple","orange":[2,3,4],True:False,None:"true",} #method get
print(pairs.get("orange"))
print(pairs.get(7))
print(pairs.get(12345, 'not in dictionary'))
for i in count(5): #itertools
print(i)
if i >=10:
break
nums=list(accumulate(range(10)))
print(nums)
print(list(takewhile(lambda x:x<=6,nums)))
letters="a","b"
print(list(product(letters,range(3))))
print(list(permutations(letters)))
birth = [1981,1949,1955,1971,1975,2004] #functions list
def birth_year():
return 2050 -len['']
for int in birth:
result=list(map(lambda x: 2050-x,birth))
print(result)
lsit={"pierre":40,"alfred":21,"thierry":61,"laurent":38}
if "alfred" in lsit:
print ("alfred found")
while len(lsit)>=4 or lsit%2==0:
lsit_n=(40,21,61,38)
if str not in lsit_n :
print("les noms sont",lsit)
break
else:
print("impossible d'énumérer")
def decor (func): #decorators
def wrap():
print('************')
func()
print('************')
return wrap
def print_text():
print('hello')
decorated=decor(print_text)
decorated()
cruise={'ferry','paquebot','ocean','sea','oasis of the seas'.upper()} #sets
cruise.add('jet-ski')
holiday={'beach','sand','sunset','cocktail','pool'.upper(),'sea'}
holiday.add('sleep')
print(cruise | holiday,cruise-holiday)
def countdown(): #generators
i=5
while i>0:
yield i
i -=1
for i in countdown():
print(i)
def numbers(x):
for i in range(x):
if i%2==0:
yield i
print(list(numbers(11)))
def apply_twice (func,arg):#functional programming
return func(func(arg))
def add_five(x):
return x+5
print(apply_twice(add_five,2))
try: #exceptions
print(8)
assert (8/0)
except ZeroDivisionError:
print("division par 0")
finally:
print('code will run no matter what')
class student: #POO #methods
def __init__(self,name,level):
self.name=name
self.level=level
def biology(self):
self
print(self.name)
obj=student('john says hi',3)
print(obj.name)
class baby: #inheritance
def bark(self):
print('helllloooo')
class school(baby):
def park(self):
print('areeeeuuh')
class teen(baby):
def accent(self):
print('ooooooohey')
c=teen()
c.accent()
c=school()
c.park()
c=baby()
c.bark()
#re
ph="la mer a une température idéale"
pattern=r"mer"
if re.match(pattern,"mer"):
print('Match')
else:('No match')