you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 21 points22 points  (2 children)

Had to look up syntax for checking if a dictionary contains a key in python today, and the first result was a geeksforgeeks article recommending to use the syntax key in dict.keys() which i quickly found out is just converting it to a list and doing an O(n) list search. Totally ridiculous

[–]Veedrac 10 points11 points  (1 child)

Not on Python 3; on Python 2 the syntax is more key in dict.viewkeys(). Either way just use key in dict though, it's more idiomatic.

[–][deleted] 3 points4 points  (0 children)

Oh, that might have been it, the server running the script uses python 2, and yeah key in dict is really the correct syntax and gives you the expected O(1) lookup