Minh Doan Minh Doan - 1 year ago 80
Python Question

Python simple code arrangement

The following code:

list1=['hello','bye']
list2=['john','dave','joe','bob']

for say in range (2):
print list1[say]
for name in range (4):
print list2[name]


The result is:

hello
bye
john
dave
joe
bob


How to arrange the code so the result will be like this:

hello
john
dave
joe
bob
bye
john
dave
joe
bob


I'm new to coding. Thanks for your help

Answer Source
list1=['hello','bye']
list2=['john','dave','joe','bob']

for listitem1 in list1:
    print(listitem1)
    for x in list2:
        print(x)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download