Feature Requests item #1184678, was opened at 2005-04-17 11:05 Message generated for change (Comment added) made by rhettinger You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1184678&group_id=5470
Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Poromenos (poromenos) Assigned to: Nobody/Anonymous (nobody) Summary: "replace" function should accept lists. Initial Comment: It would be nice if the "replace" function accepted lists/ tuples and replaced each item in the "old" list with the corresponding item in the "new" list. ---------------------------------------------------------------------- >Comment By: Raymond Hettinger (rhettinger) Date: 2005-04-18 17:20 Message: Logged In: YES user_id=80475 I'm -1 on complicating str.replace()'s API for functionality that substantially duplicates that offered by str.translate(): >>> "Hello world".translate(string.maketrans('ed', 'ae')) 'Hallo worle' ---------------------------------------------------------------------- Comment By: Poromenos (poromenos) Date: 2005-04-18 16:15 Message: Logged In: YES user_id=267121 Hmm, actually I was requesting that string.replace() accepted lists of substitutions, like so: >>> "Hello world".replace(["e", "d"], ["a", "e"]) 'Hallo worle' But your suggestion would also be very useful. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2005-04-18 16:11 Message: Logged In: YES user_id=80475 Are you requesting that lists be given a replace() method that parallels the replace() method for strings? def replace(self, old, new): result = [] for elem in self: if elem == old: result.append(new) else: result.append(elem) self[:] = result ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1184678&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com