Home>

Hello everyone, I ran into a problem, there are 3 lists, from each list you need to get the first element, and add to the line, and so on with a step of +1, I tried to solve it in this way (see the code below)

first_list= ['10', '11', '12']
second_list= ['21', '22', '23']
third_list= ['34', '35', '36']
def main ():
    list_index= 0
    while len (third_list):
        command_string= "some_data:"
        for elem in first_list:
            str1= command_string + elem [list_index] + ""
            for elem in second_list:
                str2= str1 + elem [list_index] + ""
                for elem in third_list:
                    str3= str2 + elem [list_index] + ""
        print (str3)
        list_index= list_index + 1

but at the output I just get the first digits of the list items, and an error:

some_data: 1 2 3
some_data: 2 3 6
Traceback (most recent call last):
  File "main.py", line 21, in <
module >
    main ()
  File "main.py", line 11, in main
    str1= command_string + elem [list_index] + ""
IndexError: string index out of range

As a result, I expect a similar string: "some_data: the first element of the first list. the first element of the second list, and so on", "some_data: the second element of the first list. The second element of the second list, etc." there can be more than three lists. lists of the same size. I will be grateful for the tips, thanks.

Add the expected result to the question

gil9red2021-11-25 03:33:47

Thanks for the clarification, but it's better not to describe in text, but in a line, like from the console :)

gil9red2021-11-25 03:33:47

thanks for the hint, I generally expected to see the answer tomorrow afternoon, and not right in a minute

Merser52021-11-25 03:33:47

The stars are so aligned that you wrote right before I wanted to see what's new on the stack :)

gil9red2021-11-25 03:33:47