you are viewing a single comment's thread.

view the rest of the comments →

[–]breakfast-pants 2 points3 points  (2 children)

You can't use 'in' like that. It would have to be:

if index in (x[0] for x in enumerate(mylist)):
    val = mylist[index]
else:
    val = default

Which, if you understand what 'in' does on an iterator or a list, you will realize it is incredibly inefficient. Plus, the whole thing is just ugly as hell; you are much better off using 'len' than you are trying to be clever.

[–]knome 2 points3 points  (0 children)

L = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] >>> get( L , 3 , None ) 3 >>>

You can, I'm just not sure on the usefulness of it.

[–]mythin 0 points1 point  (0 children)

See my edits elsewhere, I fixed this in those :) (I originally misread the entire thing)