Reputation: 53
I have a list of list that I want to display as a string. This list:
my_list = [[7, 'd'], [3, 's']]
I want to display without the brackets and commas like this:
7d 3s
How?
Upvotes: 2
Views: 1682
Reputation: 2804
I would come to this short answer:
' '.join(str(a)+b for a,b in my_list)
Upvotes: 2
Reputation: 133744
>>> my_list = [[7, 'd'], [3, 's']]
>>> ' '.join('{0}{1}'.format(x, y) for x, y in my_list)
7d 3s
The above solution is best for the specific case of any two elements but here is a more general solution which works for any number of elements in the sublist:
>>> ' '.join(''.join(map(str, sublist)) for sublist in my_list)
7d 3s
Upvotes: 7