Em Sáb, 2006-02-11 às 20:16 -0800, Raymond Hettinger escreveu: > Both work just fine. It's a personal choice when to use map() and when > to use a list comprehension. Since many itertools have the flavor of > map/filter, its use is not out of place in the itertools docs.
I know both work in the same way, but IIRC I heard someone (GvR?) saying list comprehensions should be used when possible to substitute map, filter and/or reduce. > Also, the use of map() provided an opportunity to demonstrate > operator.itemgetter(). While not essential to this example, it is > helpful with several other tools (especially those with a key= > argument). Itertools provide a kind of iterator algebra and > itemgetter() is an essential part of that algebra; hence, it is > appropriate that it be included in itertool examples. > > If your taste says otherwise, that's okay. Program however you want. > If reading the examples helped you understand the toolset, then the > docs accomplished their goal. IMO at a first glance the it's much easier to read and understand the list comprehension, but I have to admit that if I didn't see the operator.itemgetter(1) there I would probably never known it existed. Well, so let's just leave it there, but I'll surely program with the list comprehensions ;-). Thanks for your attention, Felipe. > > Raymond > -- "Quem excele em empregar a força militar subjulga os exércitos dos outros povos sem travar batalha, toma cidades fortificadas dos outros povos sem as atacar e destrói os estados dos outros povos sem lutas prolongadas. Deve lutar sob o Céu com o propósito primordial da 'preservação'. Desse modo suas armas não se embotarão, e os ganhos poderão ser preservados. Essa é a estratégia para planejar ofensivas." -- Sun Tzu, em "A arte da guerra" -- http://mail.python.org/mailman/listinfo/python-list