Remove duplicates from input

This commit is contained in:
dmarakom6 2021-07-02 18:43:27 +03:00
parent 909a3c519b
commit e3d578080b

View file

@ -18,6 +18,9 @@ class Multi():
self.patterns = patterns self.patterns = patterns
self.files = files self.files = files
def remove_duplicates(self):
self.patterns, self.files = list(dict.fromkeys(self.patterns)), list(dict.fromkeys(self.files))
def print_matches(self): def print_matches(self):
for file in self.files: for file in self.files:
@ -39,11 +42,13 @@ class Multi():
def main(): def main():
try: try:
newMulti = Multi(sys.argv[1].split(','), sys.argv[2].split(',')) newMulti = Multi(sys.argv[1].split(','), sys.argv[2].split(','))
newMulti.remove_duplicates()
newMulti.print_matches() newMulti.print_matches()
except IndexError: except IndexError:
patterns = input("Enter patterns, separated by a comma: ") patterns = input("Enter patterns, separated by a comma: ")
files = input("Enter files, separated by a comma: ") files = input("Enter files, separated by a comma: ")
newMulti = Multi(patterns.split(','), files.split(',')) newMulti = Multi(patterns.split(','), files.split(','))
newMulti.remove_duplicates()
newMulti.print_matches() newMulti.print_matches()