Thanks all for the posts,
I guess I'm thinking in 'matrices' and in a matlab syntax. So I was trying
to get the third element of a list of lists, or lists in a dictionay in
syntax like matlab (yes, I should be using numpy or scipy).
Anyway, Alan's final suggestion (and everyone else's) has helped
"Ole Henning Jensen" <[EMAIL PROTECTED]> wrote
> What you need to do is loop all the way through your list and then
> only
> do something to every third element in the list
That's not quite what the OP asked for, he wanted the third
element from every sublist in the master list
> This is an exa
"washakie" <[EMAIL PROTECTED]> wrote
> Could someone please explain 'slices' also for dictionaries?
So far as I know slices don;t work for dictionaries directly -
dictionaries
don't have the concept of order. However you could get a list of
keys and apply a slice to that, although I'm not sure
bob gailer wrote:
> washakie wrote:
>
>> Could someone please explain 'slices' also for dictionaries?
>>
>> basically, I'd like to know how you would call every 3rd element in a list
>> of lists...
>>
Call? Do you mean that these elements are callable objects (e.g.
functions) which you wa
washakie wrote:
> Could someone please explain 'slices' also for dictionaries?
>
> basically, I'd like to know how you would call every 3rd element in a list
> of lists...
>
> My logic says: ThirdElems=List[:][2]
>
> Which to me reads, for every item in List (which are lists), return the
> third i
> Could someone please explain 'slices' also for dictionaries?
>
> basically, I'd like to know how you would call every 3rd element in a list
> of lists...
>
> My logic says: ThirdElems=List[:][2]
>
What this does is, just assign the 3 value of List to the variable.
look at this way, step by st
What you probably want is:
[elem_list[2] for elem_list in List]
If you are not sure that the list have at least three elements, you can
use something like this:
[(elem_list + [None, None, None])[2] for elem_list in List]
Which will use None as a default value.
Andreas
Am Dienstag, den 04.03.2
Could someone please explain 'slices' also for dictionaries?
basically, I'd like to know how you would call every 3rd element in a list
of lists...
My logic says: ThirdElems=List[:][2]
Which to me reads, for every item in List (which are lists), return the
third item.
but this doesn't work.
T