Hi:
Thank you very much for ALL your postings. They help a lot and now things make
sense.
Thank you
Monika
-- Original Message --
From: Alan Gauld via Tutor
To: tutor@python.org
Subject: Re: [Tutor] __getitem__
Date: Wed, 23 Nov 2016 22:25:08 +
On 23/11/16 12:25, monik
On 23/11/16 12:25, monik...@netzero.net wrote:
> I have two questions in regards to below code:
> 1. largest is a list, not a list of lists.
> [('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]
> so why when I do largest[0] I get the whole list again,
I don't know you will need to show us
On 23/11/16 12:33, monik...@netzero.net wrote:
> So numbermap.__getitem__ brings back 1, then 2,then 3, then 4.
> Then it looks up 1 ,2, 3, 4 in month but there is no key with value 1, 2, or
> or in 4.
> What am I missing?
Your problem is not with getitem but with sorted.
You need to read up o
: Re: [Tutor] __getitem__ another problem
Date: Wed, 23 Nov 2016 10:09:46 +
On 23/11/16 06:26, monik...@netzero.net wrote:
> I do not understand how numbermap.__getitem__ brings back month's key.
numbermap returns the integer corresponding to the key.
That number is then used by sorte
Hi:
I have two questions in regards to below code:
1. largest is a list, not a list of lists.
[('deit', 4), ('acer', 3), ('aceilmr', 2), ('arst', 2)]
so why when I do largest[0] I get the whole list again, not just the first item
from the list. To get the first item I have to do largest[0][0].
. Where does lambda get ky? what is ky value?
Thank you very much
Monika
-- Original Message --
From: Alan Gauld via Tutor
To: tutor@python.org
Subject: Re: [Tutor] __getitem__
Date: Wed, 23 Nov 2016 10:05:50 +
On 23/11/16 06:09, monik...@netzero.net wrote:
> Can you plea
On 23/11/16 06:26, monik...@netzero.net wrote:
> I do not understand how numbermap.__getitem__ brings back month's key.
numbermap returns the integer corresponding to the key.
That number is then used by sorted as the basis for
sorting month. So for the first entry sorted receives
the value 1, fo
On 23/11/16 06:09, monik...@netzero.net wrote:
> Can you please explain __getitem__?
__getitem__ is the operator overload for indexing.
It is like the __add__() method which overloads the + operator.
So if you imple,ent __add__() in your class you can add two instances
together using + and Pytho
>>>Nothing unless its implementation uses a while loop
>>>and index, but thats unlikely.
>>
>>
>> But that is pretty close to what actually happens, according to the
>> language ref docs for 'in' (see my previous post).
Only in certain cases. The point I was making (or trying to) is
that both
Kent Johnson wrote:
> Alan Gauld wrote:
>>>What does 'in' have to do with indexing?
>>
>>
>>Nothing unless its implementation uses a while loop
>>and index, but thats unlikely.
>
>
> But that is pretty close to what actually happens, according to the
> language ref docs for 'in' (see my previous
Alan Gauld wrote:
>>map calls, list comprehension, etc. For loops, etc.
>>work by indexing a sequences from zero to a higher
>>index until out-of-bounds is reached.
>
>
> What makes you think that?
> So far as I know for loops work by calling next on
> an iterator until nothing gets returned
> Sorry!
>
> X = stepper()
> X.data = "Spam"
Aha! The fog in my brain clears.
>> > >>> class stepper:
>> >... def __getitem__(self, i):
>> >... return self.data[i]
>> >...
>> > >>> 'p' in X
>> >True
>> >
>> >What does 'in' have to do with indexing?
To find out if 'p' is in X Python
> map calls, list comprehension, etc. For loops, etc.
> work by indexing a sequences from zero to a higher
> index until out-of-bounds is reached.
What makes you think that?
So far as I know for loops work by calling next on
an iterator until nothing gets returned, no indexes
involved.(At le
Christopher Spears wrote:
> I understand that you can use __getitem__ as a hook to
> modify indexing behavoir in a class. That's why
> __getitem__ not only affects [] but also for loops,
> map calls, list comprehension, etc. For loops, etc.
> work by indexing a sequences from zero to a higher
>
Sorry!
X = stepper()
X.data = "Spam"
--- bob <[EMAIL PROTECTED]> wrote:
> At 12:12 PM 1/16/2006, Christopher Spears wrote:
> >I understand that you can use __getitem__ as a hook
> to
> >modify indexing behavoir in a class. That's why
> >__getitem__ not only affects [] but also for loops,
> >map
At 12:12 PM 1/16/2006, Christopher Spears wrote:
>I understand that you can use __getitem__ as a hook to
>modify indexing behavoir in a class. That's why
>__getitem__ not only affects [] but also for loops,
>map calls, list comprehension, etc. For loops, etc.
>work by indexing a sequences from z
16 matches
Mail list logo