I solved a problem on Project Euler but it took about 4 minutes to run, which is above the recommended time, so I was looking through the different solutions in the forum. One of them included the symbol << in a list comprehension. This is what it looked like
blist.extend([(i << 1) + 3 for i in range(num) if alist.get(i)])
I can’t find anywhere what exactly this << symbol does. Can someone help me?
It’s a bit shift operator (Python docs), and is common among many programming languages, such as C, Java, PHP, etc. According to the Python docs:
So in your specific case,
i << 1means left shift by 1 bit, which is equivalent to multiplying by 2^1, or just 2.