Job Offer: Python Ninja or Pirate!

Simon Forman sajmikins at gmail.com
Mon Dec 10 12:16:52 EST 2007


On Dec 10, 6:10 am, "Nikos Vergas" <ni... at vergas.gr> wrote:
> > Challenge:
> > A valid response will be either a solution to the problem below, or a
> > link to some code of which you
> > are particularly proud.
>
> > Problem: In the dynamic language of your choice, write a short program
> > that will:
> >  1. define a list of the following user ids 42346, 77290, 729 (you can
> > hardcode these, but it should
> > still work with more or less ids)
> >  2. retrieve an xml document related to each user at this url "http://
> > api.etsy.com/feeds/xml_user_details.php?id="
> >  3. retrieve the data contained in the city element from each xml
> > document
> >  4. keep a running total of how many users are found in each city
> >  5. display the total count of users living in each city
>
> > You can assume user ids are valid and that the url is available. The
> > output should look something
> > like:
>
> > Charlotte: 1
> > New York: 2
>
> i wanted to make it a one liner, but i had to import modules :(
>
> import sys, xml, urllib
>
> dummy = [sys.stdout.write(city + ': ' + str(num) + '\n') for city, num in
> set([[(a, o.count(a)) for a in p] for o, p in [2*tuple([[city for city in
> ((xml.dom.minidom.parseString(urllib.urlopen('http://api.etsy.com/feeds/xml_user_details.php?id='
> + str(id)).read()).getElementsByTagName('city')[0].childNodes + [(lambda
> t: (setattr(t, 'data', 'no city'),
> t))(xml.dom.minidom.Text())[1]])[0].data.lower().replace('  ', ' ') for id
> in [71234, 71234, 71234, 71234, 71234, 71234, 42792])]])]][0])]


Cute, now can you make it readable?  ;-)

~S



More information about the Python-list mailing list