>>14303779>Why does Python perform poorly at for loops?!IIRC, it's because it's dynamically typed. So on each iteration of the loop, so if you do something like:
>x = [1,2,3.1415,"abc",[[3]]]>for i in x:> 2 * iThen for each i the interpreter has to check an attribute called PyObject (or some other C struct like that) to understand what the type is, and then has to decide how to correctly handle 2*i, which in this case has 4 different possible implementations. So it has to do quite a bit of work at runtime.
>Why wouldn't they all just function the same way?Different design goals.
>Does this mean certain algorithms are faster in some languages than others?The time complexity of an algorithm is independent of the language, so if you implement a binary search in either Python or C, it'll still have ln(n) complexity. However, this is how the time the algorithm grows as the inputs change, so for example, if in C you it takes 1 microsecond search for a value in a list of 2 elements, then you should expect it to take about 5 microseconds for 100 elements (since ln(100) ~ 4.6). However in python, your base case would just take longer, say 10 microsecond for 2 elements and about 5o microseconds for 100 elements (again because ln(100) ~ 4.6)
Does that answer all your questions?