-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_methods.py
91 lines (63 loc) · 2.93 KB
/
list_methods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Functions to manage and organize queues at Chaitana's roller coaster."""
from typing import List
def add_me_to_the_queue(
express_queue: List[str], normal_queue: List[str], ticket_type: int, person_name: str
) -> List[str]:
"""Add a person to the 'express' or 'normal' queue depending on the ticket number.
:param express_queue: list - names in the Fast-track queue.
:param normal_queue: list - names in the normal queue.
:param ticket_type: int - type of ticket. 1 = express, 0 = normal.
:param person_name: str - name of person to add to a queue.
:return: list - the (updated) queue the name was added to.
"""
match ticket_type:
case 0:
return normal_queue + [person_name]
case 1:
return express_queue + [person_name]
return [] + [person_name]
def find_my_friend(queue: List[str], friend_name: str) -> int:
"""Search the queue for a name and return their queue position (index).
:param queue: list - names in the queue.
:param friend_name: str - name of friend to find.
:return: int - index at which the friends name was found.
"""
return queue.index(friend_name)
def add_me_with_my_friends(queue: List[str], index: int, person_name: str) -> List[str]:
"""Insert the late arrival's name at a specific index of the queue.
:param queue: list - names in the queue.
:param index: int - the index at which to add the new name.
:param person_name: str - the name to add.
:return: list - queue updated with new name.
"""
new_queue: List[str] = queue.copy()
new_queue.insert(index, person_name)
return new_queue
def remove_the_mean_person(queue: List[str], person_name: str) -> List[str]:
"""Remove the mean person from the queue by the provided name.
:param queue: list - names in the queue.
:param person_name: str - name of mean person.
:return: list - queue update with the mean persons name removed.
"""
new_queue: List[str] = queue.copy()
new_queue.remove(person_name)
return new_queue
def how_many_namefellows(queue: List[str], person_name: str) -> int:
"""Count how many times the provided name appears in the queue.
:param queue: list - names in the queue.
:param person_name: str - name you wish to count or track.
:return: int - the number of times the name appears in the queue.
"""
return queue.count(person_name)
def remove_the_last_person(queue: List[str]) -> str:
"""Remove the person in the last index from the queue and return their name.
:param queue: list - names in the queue.
:return: str - name that has been removed from the end of the queue.
"""
return queue[-1]
def sorted_names(queue: List[str]) -> List[str]:
"""Sort the names in the queue in alphabetical order and return the result.
:param queue: list - names in the queue.
:return: list - copy of the queue in alphabetical order.
"""
return sorted(queue)