-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.py
More file actions
49 lines (40 loc) · 1.56 KB
/
Copy pathtest4.py
File metadata and controls
49 lines (40 loc) · 1.56 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
import numpy as np
# do not change/remove this class
class EventNode:
def __init__(self, event_name, attendees):
self.event_name = event_name
self.attendees = attendees
self.next = None
class Solution:
@staticmethod
def calculate_leaderboard(head : EventNode):
# place your code here
result = dict()
while(head != None):
for attendee in head.attendees:
if attendee not in result:
result[attendee] = 0
else:
result[attendee]+=1
head = head.next
print(result)
sort_alpha = sorted(result.keys())
print(sort_alpha)
result_alpha = dict()
for name in sort_alpha:
result_alpha[name] = result[name]
print(result_alpha)
reuslt_sort = {k: v for k, v in sorted(result_alpha.items(), key=lambda item: item[1], reverse=True)}
# sort_score = {k: v for k, v in sorted(sort_alpha.items(), key=lambda item: item[1])}
# print(sort_score)
print(reuslt_sort)
return list(reuslt_sort.keys())
coding_workshop = EventNode("Coding Workshop", ["Alice", "Bob", "Charlie"])
tech_talk = EventNode("Tech Talk", ["Charlie", "Alice", "David"])
hackathon = EventNode("Hackathon", ["Emma", "Charlie", "Alice"])
# Linking the nodes
coding_workshop.next = tech_talk
tech_talk.next = hackathon
# Calculating and printing the leaderboard
print("Test 1 Leaderboard:")
print(Solution.calculate_leaderboard(coding_workshop))