-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-12-23.py
58 lines (45 loc) · 1 KB
/
11-12-23.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
# list comprihention
#[expression:loop:condition]
x=[1,2,3,4,5,6,7,8,9,10]
tableof2=[]
for item in x:
tableof2.append(item*2)
print(tableof2)
table=[item*2 for item in x]
print(table)
#program 2
birthyear=[2000,2001,2002,2003,2004,2005,2006]
age=[]
for item in birthyear:
age.append(2023-item)
print(age)
ages=[2023-item for item in birthyear]
print(ages)
#program 3
marks=[11,22,33,44,55,66,77,88,99,110]
above50=[]
for item in marks:
if item>50:
above50.append(item)
print(above50)
ab50=[item for item in marks if item>50]
print(ab50)
#program 4
names=["tavish","chainmay","aman","ankit","shryenshi","vaidahi","kirtish"]
first=[]
for item in names:
first.append(item[0])
print(first)
fl=[item[0] for item in names]
print(fl)
#program 5
h1=[11,2,33,457,3795,89,98,77,88,99,400,839,98,9487,948,834808,49384,20]
a1=[]
for item in h1:
if item % 2 == 0:
a1.append("even")
else:
a1.append("odd")
print(a1)
h=["even" if item % 2==0 else "odd" for item in h1 ]
print(h)