My question seems to be very simple, but I still don't find the right answer for me. Maybe, if I am writing the specific explanation somebody can help me out.
So following case:
I have this list a
(if I do print(type(a)
) it will also return "class list"), which I have manually inserted into the script. Unfortunately if I do this programmatically it will always return list b
in the example, which then isn't recognized correctly by the following program.
a = [1,2,3,4,5,6,7,8,9,10]
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
My question is: How do I remove the spaces in list b
to be like list a
?
CodePudding user response:
If the lazy automatic formatting doesn't suit your needs, then do it yourself:
print( '[' (','.join(str(i) for i in b)) ']' )
CodePudding user response:
You can convert list to a string and then use the replace function to replace all ', ' to ','.
a = [1, 2, 3]
new_list = str(a)
print(new_list.replace(", ", ","))