简体   繁体   中英

Printing a list of list without brackets in python

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?

>>> 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

我会来这个简短的回答:

' '.join(str(a)+b for a,b in my_list)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM