Mixing lists alternately

Asked 2 years ago, Updated 2 years ago, 40 views

I'd like to take turns shuffling the list from Python For example, if you have two lists, list1=[a,c,e] list2=[b,d,f] Mix list1 and list2 [a,b,c,d,e,f] That's what I want to do What should I do?

python list

2022-09-22 14:02

1 Answers

list1=['a','c','e']
list2=['b','d','f']
list3=list1+list2
list3.sort()
print(list3)
------------------------------
['a', 'b', 'c', 'd', 'e', 'f']

If you add lists 1 and 2, the two lists are combined. Sort the merged list using the sort function sort is sorted in order.


2022-09-22 14:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.