How to print a list of tuples with no brackets in Python

前端 未结 4 1366
[愿得一人]
[愿得一人] 2020-12-14 02:41

I\'m looking for a way to print elements from a tuple with no brackets.

Here is my tuple:

mytuple = [(1.0,),(25.34,),(2.4,),(7.4,)]
<
4条回答
  •  猫巷女王i
    2020-12-14 03:23

    I iterate through the list tuples, than I iterate through the 'items' of the tuples.

    my_tuple_list = [(1.0,),(25.34,),(2.4,),(7.4,)]
    
    for a_tuple in my_tuple_list:  # iterates through each tuple
        for item in a_tuple:  # iterates through each tuple items
            print item
    

    result:

    1.0
    25.34
    2.4
    7.4
    

    to get exactly the result you mentioned above you can always add

    print item + ','
    

提交回复
热议问题