Comprehensions

my_list = [ ]
for i in range(1,20):
my_list.append(i)
print(my_list)
my_list=[i for i in range(1,20)]
print(my_list) #nəticə:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
my_list = [1,2,3,4,5,6]
new_list = [ ]
for i in my_list:
if i%2 == 0:
new_list.append(i)
print(new_list) #nəticə [2, 4, 6
]
my_list=[1,2,3,4,5,6]
new_list=[i for i in my_list if i%2 == 0]
print(new_list) #nəticə [2, 4, 6]
my_list=[1,2,3,4,5,6]
new_list=[i*2 if i % 2 == 1 else i*3 for i in my_list ]
print(new_list) #nəticə [2, 6, 6, 12, 10, 18]
new_list = [ ]
for i in range(3):
temp = [ ]
for j in range(3):
temp.append(i)
new_list.append(temp)

print(new_list) #nəticə [[0, 0, 0], [1, 1, 1], [2, 2, 2]]
new_list=[ [ i for j in range(3) ] for i in range(3) ]print(new_list) #nəticə [[0, 0, 0], [1, 1, 1], [2, 2, 2]]

--

--

--

Proqramlaşdırma mərkəzi

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Coders Azerbaijan

Coders Azerbaijan

Proqramlaşdırma mərkəzi

More from Medium

How I became a self taught programmer at the age of 15

What makes a good data scientist?

What Do You Mean, “Bad Data”?

Why is data science actually a science?