-1
list1 = [1,2,3,4,5,6]
list2 = [7,8,9,10,11,12]
list3 = ["a","b","c","d","e","f"]

for-loops and get the string like this

text1 = print('this is 1 and 7 and a')
text2 = print('this is 2 and 8 and b')
text3 = print('this is 3 and 9 and c')
text4 = print('this is 4 and 10 and d')

thanks you guy :D

3 Answers3

0

Assuming all the lists are the same length, you could iterate over the indexes:

for i in range(len(list1)):
    print (f'This is {list[1]} and {list2[i]} and {list3[i]}')
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Try zip

for first, second, third in zip(list1, list2, liste):
    print(first, second, third)
Watanabe.N
  • 1,549
  • 1
  • 14
  • 37
0

You can use zip:

list1 = [1,2,3,4,5,6]
list2 = [7,8,9,10,11,12]
list3 = ["a","b","c","d","e","f"]

for a,b,c in zip(list1, list2, list3):
    print(f'This is {a} and {b} and {c}')

output:

This is 1 and 7 and a
This is 2 and 8 and b
This is 3 and 9 and c
This is 4 and 10 and d
This is 5 and 11 and e
This is 6 and 12 and f

as dictionary:

dic = {f'text{i+1}':  f'This is {a} and {b} and {c}'
       for i, (a,b,c) in enumerate(zip(list1, list2, list3))}

output:

{'text1': 'This is 1 and 7 and a',
 'text2': 'This is 2 and 8 and b',
 'text3': 'This is 3 and 9 and c',
 'text4': 'This is 4 and 10 and d',
 'text5': 'This is 5 and 11 and e',
 'text6': 'This is 6 and 12 and f'}
mozway
  • 194,879
  • 13
  • 39
  • 75