[attribution lost] > There is no built-in dict(); if it existed i suppose it would do > the opposite of x.items(); again a weak argument, though i might > have found such a function useful once or twice. [Guido] > Yeah, it's not very common. Dict comprehensions anyone? > > d = {k:v for k,v in zip(range(10), range(10))} # :-) It's very common in Perl code, but is in no sense the inverse of .items() there: when you build a dict from a list L in Perl, it acts like Python {L[0]: L[1], L[2]: L[3], L[4]: L[5], ... } That's what seems most practical most often; e.g., when crunching over text files with records of the form key value (e.g., mail headers are of this form; simple contact databases; to-do lists segregated by date; etc), whatever fancy re.split() is used to break things apart naturally returns a flat list. A list of two-tuples is natural only if it was obtained from another dict's .items() <0.9 wink>. pushing-the-limits-of-"practicality-beats-purity"?-ly y'rs - tim
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4