Last active
October 20, 2017 14:09
Star
You must be signed in to star a gist
Enhanced List
This file contains 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