How To Solve Valueerror In Python
I'm working on a image search engine application, I have the code in separate .py files and it's working fine. But I want to optimize it. When I use the function below, it's giving
Solution 1:
So, my guess is that this part:
zip(*sorted(zip(res_lst_srt['values'], res_lst_srt['keys'])))
is returning an empty list to any of the zip
s:
>>> foo, bar = []
Traceback (most recent calllast):
File "<stdin>", line 1, in<module>
ValueError: need more than 0valuesto unpack
Now, if you want to populate res_lst_srt
(as it seems I understood from your question), why don't you make it simpler?
>>>values=[1,2,3]>>>keys=['a', 'b', 'c']>>>my_dict = dict(zip(keys, values))>>>my_dict
{'a': 1, 'c': 3, 'b': 2}
(values
here would be res_lst_srt['values']
, keys
would be res_lst_srt['keys']
and my_dict
would be res_lst_srt
. No? Shouldn't that work?
Solution 2:
Your issue can be found by looking at this simple case.
>>> a, b = tuple() # or you could write a, b = []
Traceback (most recent call last):
File "<pyshell#319>", line 1, in <module>
a, b = tuple()
ValueError: need more than 0 values to unpack
>>>
The length of values on one side of the equals operator must match the other.
So its clear that the values returned by..
zip(*sorted(zip(res_lst_srt['values'], res_lst_srt['keys'])))
..end up returning an empty list/tuple. Which is causing you grief.
Post a Comment for "How To Solve Valueerror In Python"