I have a list of lists below
p=[[1,2,3,4],[2,3,4,1]]
How do I put the sublist into a string?
For example, desire result is:
p=["1234","2341"]
It can be done by converting every integer to string and joining the strings:
p = [''.join(map(str, sub_list)) for sub_list in p] # ['1234', '2341']
Ever every nested list, like [1, 2, 3, 4], map(str, [1, 2, 3, 4]) would create a list of strings. In this example: ['1', '2', '3', '4']. Using the join function, the string-numbers are mapped into a single string, '1234'.
Since this operation is performed for every sub-list, the result is a a list of the joined strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With