function taking scalar or list argument beliavsky at
Mon Aug 23 19:39:26 CEST 2004

I can define a function that transforms either a scalar or each element in
a list as follows:

def twice(x):
        return map(twice,x)
        return 2*x

print twice(3) # 6
print twice([1,4,9]) # [2,8,18]

Is this good style? I intend to define many functions like this and want
to use the right method. Thanks.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

More information about the Python-list mailing list