python needs leaning stuff from other language

Luis Alberto Zarrabeitia Gomez kyrie at uh.cu
Thu Apr 2 19:02:55 EDT 2009


Quoting Esmail <ebonak at hotmail.com>:

> Diez B. Roggisch wrote:
> >
> > some_list[:] = []
> 
> I agree that this is nice and clear, 

Not very intuitive, though, until you learn the syntax.
(but, slice accessing and slice assignment are among the first few things one
learns about python anyway, and once you learn it, it seems more than natural)

> but as a relative newbie
> wouldn't
> 
> some_list = []
> 
> be also acceptable (and pythonic?)?

Pythonic, yes.
Acceptable, it may not be (depending on the problem). And I would adventure that
if someone needs to clear a list instead of creating an empty one, its likely
that someone is facing one of those problems (i.e: clearing a list that you got
as a function argument, or playing with os.walk).

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie




-- 
Participe en Universidad 2010, del 8 al 12 de febrero de 2010
La Habana, Cuba 
http://www.universidad2010.cu




More information about the Python-list mailing list