Last active
October 20, 2017 14:09
-
-
Save DeflatedPickle/f13ef7f42dd4aa562069bb6f094e423f to your computer and use it in GitHub Desktop.
Enhanced List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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