3 ms·
As others have pointed out, sum() is the right thing for (2), and groupby() could be used to build a real partition for (6). Clearly I should have tried this in
by MostAwesomeDude 15y ago
As others have pointed out, sum() is the right thing for (2), and groupby() could be used to build a real partition for (6). Clearly I should have tried this in the morning, after a full night's sleep. :3 More seriously, for (2), (9), and (10), I was trying to answer with similar one-liners that have the same kind of complexity and results, to show that Python's syntax isn't that scary.
Also, I should note that there is a one-liner for using urllib and lxml to grab and parse an XML file, but there's another one-liner using Twisted to do the same thing; it depends on your context. Why do you want the XML? What are you doing with it? That is something important that needs to be considered.