[Tutor] A couple beginner questions.
Eric Henry
ehenry@imt.net
Wed, 26 Sep 2001 00:21:51 -0600
Sean 'Shaleh' Perry wrote:
> this one is straight from the tutorials.
>
> [1,2,3] is a list in python. There are two handy functions in python for
> lists:
>
> map(func,list) -- every item in list is passed to func() as an argument this is
> equivalent to 'for i in list: func(i)'
>
> reduce(func, list) -- starting with the first two elements, pass two elements
> to func and keep a cumalitive result. This is the same as 'total =
Ah, ok. Thanks, that was exactly what I needed. :)
> Hmmm, sounds like a homework problem (-: Consider making the middle element
> the key and the each list the data. So dict[3] -> [1,3,4]. Of course this
> only works when the keys are not dups.
Hmm. I'm not sure that will do what I need. I'm not always gonna know
what the number in the middle column is. Sometimes I'll need to give it
the number in the first column, and get the value from the second
column, other times the value in the third column, and get back both the
first and second column values.
Oh, and actually it's not homework. :) I'm a sociology student, just
trying to learn a bit about programming by doing some stuff to solve
some problems I come across a lot, basically just statistics related
stuff. Usually I just open up SPSS and do it, but I needed something to
work on while I'm learning, so I'm duplicating a bunch of stuff.
Probably pretty badly too. ;)
Thanks again.
Eric Henry