[Tutor] 2d list matrix 7 x 75 problem
Max Noel
maxnoel_fr at yahoo.fr
Sun Mar 6 13:42:35 CET 2005
On Mar 6, 2005, at 09:49, Dave S wrote:
> so I thought I would be clever with ...
> >>> a=[0]*5
> >>> a
> [0, 0, 0, 0, 0]
> >>> b=[a[:]]*5
>
> same problem.
>
> It seems realy simple but how do I generate a 7 x 75 list matrix ?
>
> Dave
Try this:
>>> a = [''] * 5
>>> b = [a[:] for i in range(5)]
>>> b
[['', '', '', '', ''], ['', '', '', '', ''], ['', '', '', '', ''], ['',
'', '', '', ''], ['', '', '', '', '']]
>>> b[0] is b[1]
False
List comprehensions. Gotta love 'em... ^^
> Is there a more elegant solution to
>
> if string == 'sun' or string == 'mon' or string == 'tue' or string ==
> 'wed' or string == 'thu' or string == 'fri' or string == 'sat':
Yes, there is.
if a in ('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'):
(also works with a list or a dictionary)
-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
More information about the Tutor
mailing list