+ 1

[Python] I have 2 lists how can I merge them in one list.

a=[1,2,3] b=[a,b] and I need to make a new list as new_list=[1a,1b,2a,2b,3a,3b] lists will be longer and its not easy to write new_list by hand. If somebody can help me I will be glad.thanx in advance

26th Sep 2018, 5:39 PM
Art
9 Respuestas
+ 8
Art you can get modules using help("modules") but this doesn't work on Sololearn and you can use this code https://code.sololearn.com/c071JeXy6LcW/?ref=app
26th Sep 2018, 6:08 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 7
from itertools import product l1 = list('123') l2 = list('ab') for i in l1: for j in l2: print(i+j) print() for i in product(l1, l2): print("".join(i))
26th Sep 2018, 5:51 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 4
Roneel You can do everything by hand, but whenever there's a predefined module, it's usually more efficient to use it because it is optimized for the task
26th Oct 2018, 8:51 PM
Anna
Anna - avatar
+ 3
Mert Yazıcı and Anna thank you very much but Im new in Python and dont have any experiences about any coding,Im watching the lessons but Im so confused about that,everytime we are importing something (is that moduls?) and how we know about what we can import? is there any list for that?
26th Sep 2018, 6:01 PM
Art
+ 3
You'll know the most important modules over time. You can read all about itertools here: https://docs.python.org/3.1/library/itertools.html
26th Sep 2018, 6:05 PM
Anna
Anna - avatar
+ 3
Thank you for your helps I need to study hard I guess :)
26th Sep 2018, 6:30 PM
Art
26th Sep 2018, 5:52 PM
Anna
Anna - avatar
26th Oct 2018, 8:00 PM
Roneel
Roneel - avatar
+ 2
I learnt something new. thanks!
26th Oct 2018, 9:02 PM
Roneel
Roneel - avatar