Created
December 19, 2017 17:15
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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