Fast Python loops
python.org
Fast Python loops
1–10 of 54 posts
Re: Fast Python loops
#2Re: Fast Python loops
#3Re: Fast Python loops
#4Edit: Yup, it is. 3x faster. https://gist.github.com/anonymous/18e372e8d0173e77b5c405920d...
Re: Fast Python loops
#5Re: Fast Python loops
#6"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 range function is significant. Can anyone enlighten me about this and what the technique is? Does this technique have a name?Re: Fast Python loops
#7Re: Fast Python loops
#8Interesting read! I'm still missing what "B" in the Python code referring to as well.
He's using it because it converts the int 65 to the string 'A', then toString() to join all the array elements together.
https://docs.python.org/2/library/array.html
See my other post though, it's not the fastest way to do this in python.
Re: Fast Python loops
#9I thought list comprehension were faster than loops?
Re: Fast Python loops
#10Interesting read! I'm still missing what "B" in the Python code referring to as well.
array.array isn't a normal python array. It's an optimized type/object where all the elements of the array are of the same type. The 'B' is a format string that indicates what type you want the elements to be. B == unsigned char He's using it because it converts the int 65 to the string 'A', then toString() to join all the array elements together. https://docs.python.org/2/library/array.html See my other post though,…