Reputation: 103
From this list of tuples:
lst = [('abc',1), ...]
I want to print out
abc 1
I have tried
var = lst[0]
print (var[0], var[1])
Is there a direct way to print the desired result?
Another way is using for loop but I think it is completely useless clutter for this.
Upvotes: 0
Views: 249
Reputation: 761
I have many answers! If you only want to print the first one, you can do:
lst = [('abc',1),('efg',99)]
print(*lst[0]) # Output: abc 1
If you want to do that with each element of the list:
lst = [('abc',1),('efg',99)]
for e in lst:
print(*e)
Finally, if you want to print this tuple but still save it in a variable, you can do:
lst = [('abc',1),('efg',99)]
print(*(var:=lst[0])) # Output: abc 1
print(var) # Output: ('abc', 1)
print(*var) # Output: abc 1
Upvotes: 1