Elastic Search No server available, list index out of range
Tag : python , By : user187301
Date : March 29 2020, 07:55 AM
Hope this helps I'm trying to get a simple example working with elastic search using pyes, but I'm having trouble getting the starting examples working. I'm following the documentation found here: http://pyes.readthedocs.org/en/latest/manual/usage.html , This will work: ES(server=[('http', 'localhost', 9200)])
|
Python fastest search in a list of tuple/list that returns the index
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Since you list at index 0 is sorted you can use bisect module to find the index in O(log N) time: In [33]: import bisect
In [34]: lst = [1, 21, 54, 55, 93, 99, 284, 393, 964, 1029, 1214, 1216, 1223, 1253, 1258, 1334, 1365, 1394, 1397, 1453, 1471, 1543, 1589, 1824, 1975, 2054, 2090, 2164, 2165, 2166, 2167, 2323, 2547, 2645, 2802, 2809, 2931, 2958, 3031, 3071, 3077, 3078, 3189, 3199, 3202, 3203]
In [35]: n = 2802
In [36]: ind = bisect.bisect_left(lst, n)
In [37]: if lst[ind] == n:
...: print 'Item found at {}'.format(ind)
...:
Item found at 34
In [38]: dct = {}
In [39]: for i, x in enumerate(lst):
...: if x not in dct:
...: dct[x] = i
...:
In [40]: dct.get(n)
Out[40]: 34
In [41]: dct.get(1000) #return None for non-existent items
In [43]: lst = list(range(10**5))
In [44]: %timeit bisect.bisect_left(lst, 10**5-5)
1000000 loops, best of 3: 444 ns per loop
In [45]: %timeit lst.index(10**5-5)
1000 loops, best of 3: 1.29 ms per loop
In [46]: %timeit dct.get(10**5-5) #dct created using the new list.
10000000 loops, best of 3: 104 ns per loop
In [47]: try:
...: ind = lst.index(n)
...: print 'Item found at {}'.format(ind)
...: except IndexError:
...: pass
...:
Item found at 34
|
IndexError: list index out of range in array search
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I'm making a simple program in Python to perform a linear search. But when I run this program it gives me this error: , Your current issue is this line array = [myNumber]
array += [myNumber]
array = list(range(numCase))
|
Search a list for a range of numbers but return index of first example
Date : March 29 2020, 07:55 AM
like below fixes the issue , You can simply construct a generator: generator = (i for i,x in enumerate(mylist) if x in range(500,531))
first_index = next(generator)
>>> generator = (i for i,x in enumerate(mylist) if x in range(500,531))
>>> next(generator)
3
>>> next(generator)
6
>>> next(generator)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
generator = (i for i,x in enumerate(mylist) if x in range(500,531))
first_index = next(generator)
try:
rainday=next(generator)
except StopIteration:
print("Empty")
|
Scrapy - list returns None - index out of range
Tag : xpath , By : user118656
Date : March 29 2020, 07:55 AM
it should still fix some issue Before you access an index, make sure the corresponding list is long enough: texts = response.xpath('//div//following-sibling::p//text()').getall()
item['BusinessType'] = texts[3] if len(texts) >= 4 else 'None'
item['BusinessArea'] = texts[4] if len(texts) >= 5 else 'None'
|