Skip to content

Instantly share code, notes, and snippets.

@menon92
Created December 19, 2017 17:15
Show Gist options
  • Save menon92/fce2ddee1e7330eaf48257d510c82900 to your computer and use it in GitHub Desktop.
Save menon92/fce2ddee1e7330eaf48257d510c82900 to your computer and use it in GitHub Desktop.
# initilize a list
my_list = [1, 3, 5, 8, 11, 21]
# square each element of our list using list comprehension
square_of_my_list = [x**2 for x in my_list]
# print list
print("list:", square_of_my_list)
# একই কাজ generator expression এর মাধ্যমেও করা যায়
my_generator_object = (x**2 for x in my_list)
print ("object type is:", type(my_generator_object))
print ("generator list is: ")
# iterate item
for item in my_generator_object:
print (item)
output:
list: [1, 9, 25, 64, 121, 441]
object type is: <class 'generator'>
generator list is:
1
9
25
64
121
441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment