You have to convert the ints to strings and then you can join them:
','.join([str(i) for i in list_of_ints])
Answer from unbeknown on Stack OverflowHow to convert a list of longs into a comma separated string in python - Stack Overflow
python - "pythonic" method to parse a string of comma-separated integers into a list of integers? - Stack Overflow
Python - Convert each integer to string in list and add a comma - Stack Overflow
python - How to convert a list to a comma separated string? - Stack Overflow
Which method is best for performance when joining large string lists
How to handle a list containing both numbers and strings safely
What error occurs if join is used on a list of integers
Use [str(i) for i in range(1, 71)]. This gives you the list of str(i) for all i in range(1, 71). The function str(i) returns i as a str value instead of as an int
Seems like you want something like this,
>>> l = []
>>> for i in range(1,71):
l.append(str(i))
>>> l
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70']
Depends on your result and description, I guess your code is something like:
b = """58738121385139B
9135A4251EF0
2B631B53C383"""
print(', '.join(b))
result:
5, 8, 7, 3, 8, 1, 2, 1, 3, 8, 5, 1, 3, 9, B,
, 9, 1, 3, 5, A, 4, 2, 5, 1, E, F, 0,
, 2, B, 6, 3, 1, B, 5, 3, C, 3, 8, 3
You should use split to achieve it
print(', '.join(b.split("\n")))
result:
58738121385139B, 9135A4251EF0, 2B631B53C383
Seems like your string consists of space-separated chunks of data, You could try this:
a = b.replace(" ", ",")
I ran into a problem of providing comma separated integer to function while practising variable argument
This is the function
def multiply_num(*numbers):
print(numbers)
product = 1
for num in numbers:
product = product * num
return productNormally I would provide the value while calling the function like this
print(multiply_num(3,7,9,2))
But I had problem providing such value through the input() command. After some tinkering this worked
num = list(map(int, input("Enter numbers: ").split(",")))
print(multiply_num(*num))Even though it worked, it kind of feels like a hack, is there a better method.