[Tutor] Are you allowed to shoot camels? [kinda OT]

Chad Crabtree flaxeater at yahoo.com
Sun Feb 6 19:59:11 CET 2005


Jacob S. wrote:

>> aFuncList=[]
>> def x():
>>    print "one"
>> aFuncList.append(x)
>> def x():
>>    print "two"
>> aFuncList.append(x)
>> def x():
>>    print "three"
>> aFuncList.append(x)
>> for item in aFuncList:
>>    item()
>
>
> Okay, for this problem (it can be altered otherwise)
>
> def makefunct(stri):
>    def x():
>        print stri
>    return x
> aFuncList = [makefunct('one'),makefunct('two'),makefunct('three')]
> for item in aFuncList:
>    item()
>
> It's shorter, it works and it looks cool.
> Thanks to Jeff Shannon for the backbone of this example.

My intent in showing the above code was not to really print one two 
three, but to show that a function doesn't care what it's called.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list