Earlier quoted context omitted.
List comprehensions didn't exist when this post was written.
Python 2.0, back in 2000, had them.
This typecode was added in Python 1.5.
41–50 of 54 posts
Earlier quoted context omitted.
List comprehensions didn't exist when this post was written.
Python 2.0, back in 2000, had them.
This typecode was added in Python 1.5.
I think this is the most idiomatic way of doing it in modern python: > "".join(chr(x) for x in list_of_ints) This article is really really really out of date
I didn't know about the array library, but "".join(map(chr, list)) would have been my first choice, partly for style and partly for avoiding string concatenation (recent speedups aside).
According to archive.org this essay is from at most June 2006, which would put it at Python 2.4 or earlier. The specific performance characteristics of Python will have changed greatly in the intervening period.
This typecode was added in Python 1.5.
In the time frame spent to test these hacks I would have written a perfect C module that runs circles around it.
The author states: "There's a general technique to avoid quadratic behavior in algorithms like this. I coded it as follows for strings of exactly 256 items:" def f5(list): string = "" for i in range(0, 256, 16): # 0, 16, 32, 48, 64, ... s = "" for character in map(chr, list[i:i+16]): s = s + character string = string + s return string I am not understanding what the technique is or why using a step size of 16 in the…
The idea is to reduce the amount of redundant copying of characters: you end up doing a few more concatenations in the outer loop, but the concatenations in the inner loop are of short strings. Importantly, if you remove the restriction of the input list being "exactly 256 items", then the method is still quadratic. A linear-time algorithm for this would copy each input character exactly once, which is effectively wh…