Python Forum
Python - Search element in list without the value index
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Search element in list without the value index
#2
(Nov-04-2016, 12:31 AM)salmanfazal01 Wrote: I've used the enumeration function but that is not efficient.
Obviously if you use a O(n) method to attempt to speed up a O(logn) algorithm it isn't going to help. Basically your only choice to find those indexes is also a binary search. You can use the bisect module.

from bisect import bisect

myList = [1,4,5,6,9,10,12,14,16,19,20,22,23,24,29,30]

low = bisect(myList, int(input("Enter number with which to bisect: ")))

print(low)
Honestly I don't think this will help one bit, but it at least keeps the overall complexity of your code down to O(logn). O(logn) is incredibly fast so I don't think this will make any noticeable change whatsoever; just search the whole list. Also using an implementation of binary search to implement binary search is a little silly to say the least.
Reply


Messages In This Thread
RE: Python - Search element in list without the value index - by Mekire - Nov-04-2016, 02:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  element in list detection problem jacksfrustration 5 444 Apr-11-2024, 05:44 PM
Last Post: deanhystad
  Variable for the value element in the index function?? Learner1 8 705 Jan-20-2024, 09:20 PM
Last Post: Learner1
  Search Excel File with a list of values huzzug 4 1,291 Nov-03-2023, 05:35 PM
Last Post: huzzug
  list in dicitonary element problem jacksfrustration 3 753 Oct-14-2023, 03:37 PM
Last Post: deanhystad
Thumbs Down I hate "List index out of range" Melen 20 3,394 May-14-2023, 06:43 AM
Last Post: deanhystad
  search an element in pandas series learningPython 5 1,457 Apr-30-2023, 08:34 AM
Last Post: learningPython
  Find (each) element from a list in a file tester_V 3 1,257 Nov-15-2022, 08:40 PM
Last Post: tester_V
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,885 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  Replace for loop to search index position illmattic 5 1,322 Sep-03-2022, 04:04 PM
Last Post: illmattic
  IndexError: list index out of range dolac 4 1,954 Jul-25-2022, 03:42 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020