accessing elements in multi-dimensional sequences

Rodrigo Daunaravicius rodelrod at hotmail.com
Fri May 28 09:08:31 EDT 2004


Thank you all for you great tips! Matteo's list comprehension solution
suits best my particular problem and I'll be using it. 

On Fri, 28 May 2004 10:34:15 GMT, Matteo Dell'Amico wrote:
> You can express that as [s[:-1] for s in d].


It was great to know about the Numeric package, Peter, it will be really
useful for some of the matrix handling I'm going to need.
Anton's solution was a good brain teaser. I couldn't find in the docs what
is the meaning of the asterisk in zip(*d), though. Nothing to do with C
pointers, I guess? 


On Fri, 28 May 2004 13:58:23 +0200, Anton Vredegoor wrote:

> Rodrigo Daunaravicius <rodelrod at hotmail.com> wrote:
> 
>>Is there an elegant way to directly refer the 2nd dimension of a
>>multi-dimensional sequence (like the nth character in a list of strings).
>>An example would be deleting the newline in all the strings from a list
>>obtained through readlines without recurring to 'for' loops.
> 
> d =  ['0891931243\n', '0325443777\n', '0933477028\n',
> '0699624617\n', '0922210996\n']
> 
> #swap rows and columns, with the side effect of turning
> #strings into lists, strings must be of equal length or
> #else some information will be lost:
> 
> d1 = zip(*d)

Thanks again,
Rodrigo Daunaravicius



More information about the Python-list mailing list