Skip to content

Comments

Converts a full dict into a more Pythonic structure#16

Open
mwkuster wants to merge 13 commits intomitsuhiko:masterfrom
mwkuster:full_dict_to_list
Open

Converts a full dict into a more Pythonic structure#16
mwkuster wants to merge 13 commits intomitsuhiko:masterfrom
mwkuster:full_dict_to_list

Conversation

@mwkuster
Copy link

@mwkuster mwkuster commented Apr 3, 2017

Converts a full dict into a more Pythonic structure. In particular ensure that all list-like structures are handled as Python lists #2

@mwkuster
Copy link
Author

mwkuster commented Apr 3, 2017

In many ways a recursive version of dict_to_list, taking a full datastructure and cleaning up any pseudo-lists found in there

#without explicit array_hook
d1 = {'a': 'b', 'c': {0: '1', 1: '2', 2: {'e': 7}, 3: {2: 8}}}
d1_cleaned = {'a': 'b', 'c': ['1', '2', {'e': 7}, {2: 8}]}
self.assertEqual(phpserialize.full_dict_to_list(d1), d1_cleaned)

#with explicit array_hook
d2 = OrderedDict({'a': 'b', 'c': OrderedDict({0: '1', 1: '2', 2: OrderedDict({'e': 7}), 3: OrderedDict({2: 8})})})
d2_cleaned = OrderedDict([('a', 'b'), ('c', ['1', '2', OrderedDict([('e', 7)]), OrderedDict([(2, 8)])])])
self.assertEqual(phpserialize.full_dict_to_list(d2, OrderedDict), d2_cleaned) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant