Comprehensions in Python
squares=[x**2 for x in range(5)]
x = [i**+1 for i in range(3)]
wl=[word for sentence in python para for word in sentence.split()]
>>> [x*y for x in vec1 for y in vec2]
>>> [3*x for x in vec if x > 3]
product_list = [ i*j for i in range(10) for j in range(10,20) ]
print([[i+j for i in "abc"] for j in "def"])
squared_ints = [ e**2 for e in a_list if type(e) == types.IntType ]
33_identity_matrix=[ [ 1 if item_idx == row_idx else 0 for item_idx in range(0, 3) ] for row_idx in range(0, 3) ]
sq_dict={num: num**2 for num in range(25)}
names_comp={rol_num:details[0] for roll_num,details in stud_details.items()}
{ name[0].upper() + name[1:].lower() for name in names if len(name) > 1 }
Related Python Articles: datetime time dateutil calendar Packages Sets in Python
No comments:
Post a Comment