How to show a dictionary sorted on a value within its data?
rosuav at gmail.com
Fri Oct 3 10:09:50 CEST 2014
On Fri, Oct 3, 2014 at 5:55 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> which return non-list iterables. There's no really convenient equivalent
>> to the map() usage of "call this function with each of these args, and
>> discard the return values", as it looks very odd to do a list comp for
> map doesn't discard the return values. It accumulates them in a list, or
> yields them in a list comp.
Sure, but I've seen it used in various places to call functions where
you don't care about the return values. Technically it's identical to
the list comp, but somehow it's seen as less of an abuse.
>> Short of borrowing Pike's automap syntax:
> you mean something like this perhaps?
> print(*list_of_strings, sep='\n')
Well, no. In that one specific example, it happens to be possible to
pass all the args to one print() call and get the same effect, but
imagine some function that doesn't have that particular feature. (I
just used print for simplicity.)
>> there's really not much that's better than the original map() call. On
>> the other hand, there aren't actually all that many times when I've
>> needed to do this, and the simple for loop generally suffices:
>> for x in list_of_strings: print(x)
Yeah. That's the normal way to do things. I'm not entirely sure why I
keep seeing map() for that; there's probably a justification in
functional programming languages, or something.
More information about the Python-list