Re: lambda functions ?

2007-02-05 Thread Don Morrison
Maybe you would like a generator:

>>> def f(n):
... while True:
... n += 1
... yield n
...
>>> a = f(5)
>>>
>>> a.next()
6
>>> a.next()
7
>>> a.next()
8
>>> a.next()
9
>>>


On 2/5/07, Maxim Veksler <[EMAIL PROTECTED]> wrote:
> Hello,
> I'm new on this list and in python.
>
> It seems python has some interesting concept of "ad hoc" function
> which I'm trying to understand without much success.
>
> Take the following code for example:
>
> """
> >>> def make_incrementor(n):
> ... return lambda x: x + n
> ...
> >>> f = make_incrementor(42)
> >>> f(0)
> 42
> >>> f(1)
> 43
> """
>
> I really don't understand whats going on here.
> On the first instantiating of the object "f" where does "x" gets it's
> value? Or is it evaluated as 0? ie "x: 0 + 42"
>
> And what is the "f" object? An integer? a pointer? an Object?
> I'm coming from the C world...
>
> Could some please try (if even possible) to implement the above code
> without using "lambda" I believe it would help me grasp this a bit
> faster then.
>
> Thank you,
> Maxim.
>
>
> --
> Cheers,
> Maxim Veksler
>
> "Free as in Freedom" - Do u GNU ?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string.find for case insensitive search

2007-02-07 Thread Don Morrison
lower() is also deprecated :) oh well

On 7 Feb 2007 21:06:08 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote:
> "Johny" <[EMAIL PROTECTED]> wrote:
>
> > Is there a good way how to use string.find function to find a
> > substring if I need to you case insensitive substring?
>
> s.lower().find(substring.lower())
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string.find for case insensitive search

2007-02-07 Thread Don Morrison
string.find is deprecated as per the official python documentation.

take a look at the "re" module

On 7 Feb 2007 12:53:36 -0800, Johny <[EMAIL PROTECTED]> wrote:
> Is there a good way how to use string.find function to find a
> substring if I need to you case insensitive substring?
> Thanks for reply
> LL
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string.find for case insensitive search

2007-02-07 Thread Don Morrison
My apologies, I confused the built-in "str" with the module "string".
I was reading from the section of the 2.4.4 docs called: 4.1.4
Deprecated string functions

On 2/7/07, Robert Kern <[EMAIL PROTECTED]> wrote:
> Don Morrison wrote:
> > lower() is also deprecated :) oh well
>
> The string method .lower() is not deprecated.
>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless enigma
>  that is made terrible by our own mad attempt to interpret it as though it had
>  an underlying truth."
>  -- Umberto Eco
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: string.find for case insensitive search

2007-02-07 Thread Don Morrison
> Don Morrison wrote:
> > string.find is deprecated as per the official python documentation.
> >
> but the str.find() method isn't.
>
> > take a look at the "re" module
> >
> A possibility.
>
> regards
>  Steve

Thank you everyone. :) Johny did say "string.find" in his message, not
"str.find", but continue to proceed with flogging. thank you!
-- 
http://mail.python.org/mailman/listinfo/python-list