-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathalien.py
More file actions
81 lines (59 loc) · 2.37 KB
/
alien.py
File metadata and controls
81 lines (59 loc) · 2.37 KB
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
import list_adt as listadt
def create_alien() -> dict("messages", any):
"""
Creates an 'alien' dictionary with a list to store messages.
You can add other attributes if required
Returns:
A dictionary representing an 'alien' with a list to store messages:
{
'messages': listadt.create_list(100) # List to store messages with a maximum capacity of 100
}
"""
messages = {"messages":listadt.create_list(100)}
# provide other required implementation here
pass
def add(seq: int, msg: str, alienList: dict):
"""
Parameters:
- seq: The sequence number of the message.
- msg: The message to be added.
- alienList: The 'alien' dictionary containing the messages list.
"""
# provide implementation here
pass
def delete(seq: int, msg: str, alienList: dict):
"""
Parameters:
- seq: The sequence number of the message to be deleted.
- msg: The message to be deleted.
- alienList: The 'alien' dictionary containing the messages list.
"""
# provide implementation here
pass
def get_messages(alienList: dict) -> list[str]:
"""
Parameters:
- alienList: The 'alien' dictionary containing the messages list.
Returns:
A list of all messages in the conversation.
"""
# provide implementation here
pass
def main(filename) -> list[str]:
"""
Reads data from a file, processes it, and returns the conversation as a list.
Data is provided in the following format:
There can be multiple lines in the file, each line containing an integer and an optional string separated by a space. The integer represents the sequence number of the message, and the string represents the message itself. If the string is not provided, it is assumed to be an empty string. The sequence number 0 indicates the end of the conversation.
Process the data as follows:
- If the sequence number is 0, stop processing the file.
- If the sequence number is positive, add the message to the conversation.
- If the sequence number is negative, delete the message from the conversation.
Parameters:
- filename: The name of the file to read data from.
Returns:
A list representing the conversation obtained from the file.
"""
messages = create_alien()
# Provide your implementation here
output = get_messages(messages)
return(output)