I ask you to suggest how you can combine the elements in the tuples that are inside the list, because I found only examples with regular lists on the Internet.

Need to do from this:

[('Товар1', 155, '$',), ('Товар2', 155, '$',) ...] 

It:

 [('Товар1 155$',), ('Товар2 155$',) ...] 

    2 answers 2

    If it is very simple and without decorations, then so:

     lst = [('Товар1', 155, '$',), ('Товар2', 155, '$',)] print([(' '.join(list(map(str,x))),) for x in lst]) 

    At the exit:

     [('Товар1 155 $',), ('Товар2 155 $',)] 
    • And you can also tell me how to get just Product1 $ 155, Product2 $ 155 (without a list of tuples, just a string) at the output - Coffee inTime
    • one
      @CoffeeinTime - since we have list comprehension, then the output will still be iterable - you can do it simply: print([' '.join(list(map(str,x))) for x in lst]) - get a list with strings of the form ['Товар1 155 $', 'Товар2 155 $'] - strawdog
     lst = [('Товар1', 155, '$',), ('Товар2', 155, '$',)] 

    If you just need to print through:

     print(*[' '.join(map(str, k)) for k in lst], sep=', ') # Товар1 155 $, Товар2 155 $ 

    If you need to get a string variable then:

     lp = ', '.join(' '.join(map(str, k)) for k in lst) print(lp) # Товар1 155 $, Товар2 155 $ 

    If you need $ to write together with a digit then:

     lp = ', '.join(' '.join(map(str, k)).replace(' $', '$') for k in lst) print(lp) # Товар1 155$, Товар2 155$