Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I almost never use enumerate in python - 90%+ of the time it's the values I'm interested in - an exception might be if I'm trying to print a numbered list - and it's just handy to have the index instead of incrementing a counter. In your scenario, though, to find the location of a specific item in a list:

  >>> b=['one','two','three','four','two']
  >>> b.count("two")
  2
  >>> b.index("two")
  1
  >>> b.index("two",2)
  4


Try building binary search with .index()




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: