-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Open

Description
The best example in the Mutable and Immutable Types section of the Structuring Your Project page is:
# create a concatenated string from 0 to 19 (e.g. "012..1819")
nums = [str(n) for n in range(20)]
print "".join(nums)
It is considered the best example for being both more efficient and succinct.
Would this be a better example to use?
''.join(map(str, range(20)))
It's more succinct and is faster:
$ python -m timeit "nums = [str(n) for n in range(20)]; ''.join(nums)"
100000 loops, best of 3: 6.84 usec per loop
$ python -m timeit "''.join(map(str, range(20)))"
100000 loops, best of 3: 4.93 usec per loop
Metadata
Metadata
Assignees
Labels
No labels