Most efficient solution?
Roman Suzi
rnd at onego.ru
Mon Jul 16 23:59:10 EDT 2001
On Mon, 16 Jul 2001, Peter Hansen wrote:
>> Peter: I believe the politically correct mantra is "one obvious way
>> to do it".
>
>Yeah, I was reminded of that in reading
>http://www.amk.ca/python/writing/python-dev.html
>shortly after I posted. :(
>
> """13. There should be one -- and preferably only one -- obvious
> way to do it. """
... given your knowledge and experience.
For example, filling list with numbers could be done
in several ways:
Beginner in Python, who writes in a "language independent" style,
ex-Pascalist:
lst = [0] * 20 # init list
for i in range(1, 21):
lst[i-1] = i
Same by ex-C:
lst = [0] * 20 # init list
for i in range(0, 20):
lst[i] = i+1
Beginner in Python who know about lists:
lst = []
for i in range(20):
lst.append(i+1)
Experienced Python user favor list comprehemsions:
lst = [i+1 for i in range(20)]
Python guru, which keeps it simple because he is very stupid ;-):
lst = range(1, 21)
Where Zen applies here?
;-)
Sincerely yours, Roman Suzi
--
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Tuesday, July 17, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "...put knot yore trust inn spel chequers." _/
More information about the Python-list
mailing list