File to dict

Joe Goldthwaite joe at goldthwaites.com
Fri Dec 7 14:26:50 EST 2007


Duncan Booth wrote:
>for item in list:
>    if item == 'searched.domain':
>        return item...


mrkafk at gmail.com wrote:
>Sure, but I have two options here, none of them nice: either "write C
>in Python" or do it inefficient and still elaborate way.

I don't understand your point at all.  How does the above code equate to
writing C in Python?  Personally, I don't think that reading an entire file,
hashing its values into a dictionary just to be able to pull out one using a
dictionary get is very pythonic.  Python is about keeping things simple and
clear. Sometimes that's at the cost of efficiency but simplicity and clarity
are paramount.  Making things more complicated and much harder for others to
follow is very un-pythonic IMO.  In this case, having a simple solution
that's also much more efficient is a bonus.





More information about the Python-list mailing list