Skip to content

Instantly share code, notes, and snippets.

@DeflatedPickle
Last active October 20, 2017 14:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save DeflatedPickle/f13ef7f42dd4aa562069bb6f094e423f to your computer and use it in GitHub Desktop.
Enhanced List
class list(list):
def __init__(self, *args):
for arg in args:
self.append(arg)
def replace(self, old, new):
self[self.index(old)] = new
def replace_all(self, old, new):
for number, item in enumerate(self):
if item == old:
self[number] = new
my_list = list("hello", "bye")
print(my_list)
my_list.replace("hello", "bye")
print(my_list)
my_list.replace_all("bye", "hello")
print(my_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment