Making str.replace() accept lists - Ideas - Discussions on Python.org
Syntax of the method: str.replace(old, new, count=-1). What if replace could accept two lists instead of two strings. Often I find in code: text.replace(a, b).replace(c, d).
Syntax of the method: str.replace(old, new, count=-1). What if replace could accept two lists instead of two strings. Often I find in code: text.replace(a, b).replace(c, d).
Discussions on Python.org. Feature Proposal: Multi-String Replacement Using a Dictionary in the .replace() Method. Ideas. HicaroD (Hicro).
Note to the original code: You want to create a different number of strings. This cannot be done by using str.replace() because this function changes a string to a different string. This function cannot split or join strings which would be needed to change their number.
If I enter any other option (“b” thru “e” or “B” thru “E”) the string never gets converted. My print statement prints the original input string, not the desired replacement string. Been beating my head against the keyboard for 4 hours now.