dgilland / pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.
http://pydash.readthedocs.io
MIT License
1.28k stars 89 forks source link

`to_dict` with list of length 2 strings #187

Closed DeviousStoat closed 1 year ago

DeviousStoat commented 1 year ago

I found a behaviour of to_dict that might not be exactly what we would expect. The function first tries to use the builtin dict class for transformation and this class will try to build a dict if we pass a list of 2 elements iterators. This yields a funny result when we pass a list of length 2 strings:

>>> import pydash
>>> pydash.to_dict(['hi', 'jo'])
{'h': 'i', 'j': 'o'}

Whereas I would expect this to return {0: 'hi', 1: 'jo'} as it would do if we pass a list of strings of length != 2:

>>> pydash.to_dict(['hey', 'joe'])
{0: 'hey', 1: 'joe'}

Is this something that you would want to keep or can I try to make a PR to fix this?

dgilland commented 1 year ago

It's been awhile since I looked at that function but if a >2 element list is returned with indexes as keys, then it should be the same for a 2 element list.

The next release with type annotations will be a major breaking change anyway so fine to fix this and not worry if this behavior was being relied on. Will just note it in the changelog.

dgilland commented 1 year ago

Addressed in #188