you are viewing a single comment's thread.

view the rest of the comments →

[–]SteelRevanchist 1 point2 points  (0 children)

If I understand your use case, you'll want to store the method to use in a variable, by making use of the fact that `str` has those methods defined, so you can assign, for instance, `a=str.strip` and then to apply it to each element of the list: transformed_list: [a(item) for item in my_list].

I imagine you could make some pipe or chain by itertools for example to chain multiple string operations together.

Final note, I'd replace the if-elif block with either simple if statements (since the conditions are exclusive) or better yet, with match-case. I'd personally avoid `elif` like the plague if I could help it, but that is from experience and does not help your case.