List Comprehension - Squares

 # List comprehension

# Squares of numbers 


L = eval(input("Enter List : "))


Squares = [x**2 for x in L]

print("Squares of the given list is : ")

print(Squares)


"""

>python LC_Squares.py

Enter List : [1,2,3,4,5]

Squares of the given list is :

[1, 4, 9, 16, 25]

"""

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu