Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python3.7
- # -*- coding: utf-8 -*import
- def valid_index(i: str, lst: list):
- if len(i) == 1 and i.isdigit():
- return 0 <= int(i) < len(lst)
- def check_len(lst: list, num: int):
- return len(lst) >= num
- contacts = input().split(' ')
- while True:
- command = input().split(' ')
- if 'Print' in command:
- break
- else:
- if 'Add' in command and check_len(command, 3):
- name = command[1]
- if name in contacts:
- if valid_index(command[2], contacts):
- idx = int(command[2])
- contacts.insert(idx, name)
- else:
- contacts.append(name)
- elif 'Remove' in command and check_len(command, 2):
- if valid_index(command[1], contacts):
- idx = int(command[1])
- contacts.remove(contacts[idx])
- elif 'Export' in command and check_len(command, 3):
- if valid_index(command[1], contacts):
- idx = int(command[1])
- count = int(command[2]) + idx
- start_slice = contacts[idx:]
- if count > len(start_slice):
- print(' '.join(start_slice))
- else:
- start_slice = contacts[idx:count]
- print(' '.join(start_slice))
- if check_len(command, 2):
- if 'Normal' in command:
- print(f"Contacts: {' '.join(contacts)}")
- elif 'Reversed' in command:
- contacts = contacts[::-1]
- print(f"Contacts: {' '.join (contacts)}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement