Printing lists in python without spaces -
i doing program changes number in base 10 base 7, did :
num = int(raw_input("")) mod = int(0) list = [] while num> 0: mod = num%7 num = num/7 list.append(mod) list.reverse() in range (0,len(list)): print list[i],
but if number 210 prints 4 2 0 how rid of spaces
you can use join list comprehension:
>>> l=range(5) >>> print l [0, 1, 2, 3, 4] >>> ''.join(str(i) in l) '01234'
also, don't use list
variable name since built-in function.
Comments
Post a Comment