1

I just have a problem with adding between every 3 characters a ",".

print totalpoints
points = ','.join([totalpoints[i:i+3] for i in range(0, totalpoints, 3)])

Output:

875
TypeError: sequence index must be integer
Fragkiller
  • 589
  • 2
  • 8
  • 21
  • can you elaborate? what is `totalpoints`? If it is not a string /list, how do you suppose you would use `slice`? – Heisenberg Mar 19 '15 at 19:21

1 Answers1

1

I don't know what you are actually trying to do. But If I am not wrong, following will solve your problem.

>>> totalpoints = 875123123 
>>> totalpoints = str(totalpoints)
>>> points = ','.join([totalpoints[i:i+3] for i in range(0, len(totalpoints), 3)])
>>> points
'875,123,123'
Heisenberg
  • 1,500
  • 3
  • 18
  • 35