List array collection resolve

from Random Import the randint 

A = [the randint (-10, 10) for _ in Range (10)]   # -10 - 10 randomly generated list of length 10 
# Print (A) 
# match selected positive number 
# program: 
# slowest 
z_list = []
 for I in A:
     IF I> = 0: 
        z_list.append (I) 
Print (z_list)
 # scheme II: speed 
P = filter ( the lambda X: X> = 0, A)
 Print (List (the p-))
 Print (of the type (the p-))
 # Option three: the most speed
L = [X for X in A IF X> = 0]   # list analyzing 
Print (L) 

# dictionary parsing 
t_dict = {K: the randint (. 1, 100) for K in Range (. 1, 21 is)}   # randomly generate a dictionary 
Print (t_dict) 
s_dict = {K: V for K, V in t_dict.items () IF V> = 60 }
 Print (s_dict) 

# set parsing 
T_set = {X for X in Range (. 1, 21 is) IF X. 3% == 0}
 Print (T_set)


# Anonymous function of the lambda 
S = the lambda X: X * X
 Print (S (2 ))
 # Map method 
B_LIST = [1,2,3,4 ] 
mm = Map ( the lambda X: X IF X> 2 the else None, B_LIST)
 Print (List (mm))

 

Guess you like

Origin www.cnblogs.com/jum-bolg/p/10960894.html