Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Your code self-contradicts. Take this sample :

for si in mylistg:
    if si == 's1':
        alist = map(s1, alist)

The second line triggers the execution of the third if the test succeeds, i. e if si is a string.

But the third line then tries to map the function si to the elements of alist.

You can't have it both ways : si can't be simultaneously a string and a function...

You have to choose to have your cake or to eat it...

A possible solution is to make mylistg a list of functions, and have allowed_s a list of permissible values. You code snippet would become (something like)

alisttt=[list(map(lambda v:u(v), alist)) for u in mylistg if u in allowed_s]

with possible seasonings to prepare the arguments and return the result in pleasant form.

HTH,

Historical (paleontological) note : Common Lisp, allowing you to attach both a value and a function to the same symbol, would have allowed such a ... thing ... Not Python.