datopy.modeling.list_to_dict#
- list_to_dict( ) dict[int, object][source]#
Provide a dictionary representation of a list, using indices as keys.
Also compatible with other non-dictionary or string-like iterables.
- Parameters:
obj (list) – A list to convert to a dictionary representation.
max_items (int, default=None) – Option to impose a limit on the number of elements to iterate over. Intended use: constructing pattern-based data models from a sample.
- Returns:
The supplied list’s dictionary representation.
- Return type:
Examples
>>> from datopy.modeling import list_to_dict
>>> my_list = [1, 'two', [3], {'four': 5}] >>> list_to_dict(my_list) {1: 1, 2: 'two', 3: [3], 4: {'four': 5}}
>>> my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> list_to_dict(my_list, max_items=5) {1: 1, 2: 2, 3: 3, 4: 4, 5: 5}
>>> my_dict = dict(a=1, b='two') >>> list_to_dict(my_dict) Not running conversion since obj is already a dictionary. {'a': 1, 'b': 'two'}