+ 1

I want create a list that contain all x and y element, but what is my fault?

X = [2, 3, 5]; Y = [6, 8, 9]; Li = [i t for i in x for t in y]; Print(li)

27th Jun 2020, 7:31 PM
Abbakar_ah!!!
Abbakar_ah!!! - avatar
7 Answers
+ 2
X = [2, 3, 5]; Y = [6, 8, 9]; Li = X + Y print(Li)
27th Jun 2020, 7:37 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
+ 1
Wow! Thank you
27th Jun 2020, 7:47 PM
Abbakar_ah!!!
Abbakar_ah!!! - avatar
0
Li = [y for x in [X, Y] for y in x]
27th Jun 2020, 7:40 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
Li = [*X, *Y]   
27th Jun 2020, 7:41 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
X = [2, 3, 5]; Y = [6, 8, 9]; Li = [x for x in [*X, *Y]] print(Li)
27th Jun 2020, 7:43 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
The use of `zip` function may help. You can choose to either create a list of tuples(x, y), or create a list of values of tuple(x, y) X = [2, 3, 5]; Y = [6, 8, 9]; list_of_tuples = list(zip(X,Y)) # creates a list of tuples print(list_of_tuples) extracted_tuple_values = [] for t in zip(X, Y): extracted_tuple_values.extend(t) # adds content of each tuple in zip(X, Y) print (extracted_tuple_values)
28th Jun 2020, 1:19 AM
Ipang