schlichtanders.mylists module

Like mygenerators, there specific often needed utilities for lists. I really like the as_list decorator for an empty args generator. Also, take a look at DictList.

class schlichtanders.mylists.DictList(*list_entries, **names_to_list_of_list_entries)[source]

Bases: _abcoll.MutableSequence

firstly, this is a list secondly, this is a dict pointing to lists of elements in DictList (kept unique, i.e. automatically removing duplicates)

get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
insert(index, value)[source]
items() → list of D's (key, value) pairs, as 2-tuples[source]
iteritems() → an iterator over the (key, value) items of D[source]
iterkeys() → an iterator over the keys of D[source]
itervalues() → an iterator over the values of D[source]
keys() → list of D's keys[source]
values() → list of D's values[source]
schlichtanders.mylists.add_up(iterable)[source]
schlichtanders.mylists.as_list(gen)[source]

generator decorator which executes the generator and returns results as list

schlichtanders.mylists.deepflatten(maybe_iterable)[source]
schlichtanders.mylists.deflatten(flat_li, *original_li)[source]

rebuilds elements of flat_li to match list structure of original_li (or tuple if given as *args)

Parameters:
  • flat_li
  • original_li
Returns:

Return type:

flat_li with nesting like original_li

schlichtanders.mylists.findall(l, o)[source]

find all indices from list l where entries match specific object o

Parameters:
  • l – list to search in
  • o – object to search for
Returns:

list of indices where l[i] == o

schlichtanders.mylists.getall(l, idx)[source]

get all entries of list l at positions idx

Parameters:
  • l – list
  • idx – indices
Returns:

respective sublist

schlichtanders.mylists.remove(l, key=None)[source]
schlichtanders.mylists.remove_duplicates(l)[source]

removes duplicates in place by using del call

schlichtanders.mylists.return_list(wrapped, instance, args, kwargs)[source]
schlichtanders.mylists.sequencefy(o)[source]
schlichtanders.mylists.shallowflatten(maybe_iterable)[source]