Anyone else find themselves wishing the required output was more like [1, 2, 3, 4]? Or at least 1, 2, 3, 4, so that we could do:
>>> print str(x)[1:-1]
to slice off the brackets? (Cost: 11 keystrokes more than 'print x')
str(x) is equivalent to repr(x), which is same to `x`.Would this work?
print(len(x)*'%i ')%tuple(x)
print'%i '*len(x)%tuple(x)Would this work?print(len(x)*'%i ')%tuple(x)
It works, and actually the following is shorter:print'%i '*len(x)%tuple(x)
...because % and * have same precedences.
print" ".join(map(str,x))x=map(int,raw_input().split())
>>> r=range(10)
>>> print`r`[1::3]
>>> x=[1,2,3,4]
>>> print x
[1, 2, 3, 4]
So I've been outputting space-separated numbers like this:
>>> print" ".join(map(str,x))
1 2 3 4
But at a cost of 18-keystrokes more than print x. :-(
I just figured out that:
>>> for i in x:print i,
Only costs 12-keystrokes, but it's missing the '\n' at the end. If you need it, then:
>>> for i in x+['\n']:print i,
means that the extra seven strokes for "+['\n']" makes it worse than join/map/str.
Anyone else find themselves wishing the required output was more like [1, 2, 3, 4]? Or at least 1, 2, 3, 4, so that we could do:
>>> print str(x)[1:-1]
to slice off the brackets? (Cost: 11 keystrokes more than 'print x')
Anyone got an improvement over these methods that they'd like to suggest?