DESCRIPTION:
John has invited some friends. His list is:
s = "Fred:Corwill;Wilfred:Corwill;Barney:Tornbull;Betty:Tornbull;Bjon:Tornbull;Raphael:Corwill;Alfred:Corwill";
Could you make a program that
- makes this string uppercase
- gives it sorted in alphabetical order by last name.
When the last names are the same, sort them by first name. 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) will be:
"(CORWILL, ALFRED)(CORWILL, FRED)(CORWILL, RAPHAEL)(CORWILL, WILFRED)(TORNBULL, BARNEY)(TORNBULL, BETTY)(TORNBULL, BJON)"
It can happen that in two distinct families with the same family name two people have the same first name too.
Notes
- You can see another examples in the "Sample tests".
def meeting(s):
s=s.upper()
alist=s.split(";")
for i in range(len(alist)):
alist[i]=alist[i].split(":")
for i in range(len(alist)):
temp=alist[i][0]
alist[i][0]=alist[i][1]
alist[i][1]=temp
for i in range(len(alist)):
alist[i]=", ".join(alist[i])
alist.sort()
return "("+")(".join(alist)+")"
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Backspaces in string (0) | 2022.10.13 |
---|---|
Data Reverse (0) | 2022.10.13 |
Sum of Parts (0) | 2022.10.12 |
Make the Deadfish Swim (0) | 2022.10.11 |
IP Validation (0) | 2022.10.11 |