The dict_helper() function is a one-line function, and is less than six lines of documentation. It utilizes the named_tuple data structure, which is passed in as the keys variable and calls theĀ _make() and _asdict() functions to create our ordered dictionary after struct parses the values:
229 def dict_helper(data, format, keys):
230 """
231 The dict_helper function creates an OrderedDictionary from
232 a struct tuple.
233 :param data: The data to be processed with struct.
234 :param format: The struct format string.
235 :param keys: A string of the keys for the values in the struct
236 tuple.
237 :return: An OrderedDictionary with descriptive keys of
238 struct-parsed values.
239 """
240 return keys._asdict(keys._make(struct.unpack(format, data)))
As with most compact one-liners, it's possible to lose the meaning of the function as readability starts to decrease when more functions are called in a single line. We're going to introduce and use the built-in Python debugger to take a look at what is going on.