Apply a function to each list member?

Gaetan Corneau Gaetan_Corneau at baan.com
Thu Oct 21 17:20:04 EDT 1999


Hi,

Is there a way to do this (see "ListApply" below) with standard Python
stuff?

def f(s):
    from string import upper
    from types import StringType
    if type(s) == StringType:
        return upper(s) 
    else:
        return s


def ListApply(f, l):
    for i in  range(0, len(l)):
        l[i] = f(l[i])


l = ["aaa", "bbb", "ccc", 1, 2, 3, "xxx", "yyy", "zzz"]
print l

ListApply(f, l)
print l


Thanks,
______________________________________________________
   Gaetan Corneau
   Software Developer (Quality Assurance Team)
   BaaN  Supply Chain Solutions  
   E-mail: Gaetan_Corneau at baan.com        
   Compuserve: Gaetan_Corneau at compuserve.com  
   ICQ Number: 7395494             
   Tel: (418) 266-8252          
______________________________________________________
"Profanity is the one language all programmers know best"





More information about the Python-list mailing list