-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeetings.py
34 lines (23 loc) · 1.01 KB
/
meetings.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
'''
PROBLEM STATEMENT:
John has invited some friends. His list is:
s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill";
Make a program that makes this string uppercase
AND
Gives it sorted in alphabetical order by last name
When the last names are the same, opt to sort them by first name instead.
=? Last name and first name of a guest come in the result between parentheses separated by a comma.
So the result of function 'meeting(s)' would, for example, be:
"(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)"
'''
def meeting(s):
s = s.upper().split(';')
arr = []
for i in s:
i = i.split(':')
arr.append(f'({i[1]}, {i[0]})')
arr.sort()
return "".join(arr)
if __name__ == "__main__":
s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill";
print(meeting(s))