For most elections, names are not in alphabetical order because it is not fair t
ID: 3848506 • Letter: F
Question
For most elections, names are not in alphabetical order because it is not fair to candidates with later last names. One solution is to generate a random order of 26 letters in the alphabet and then arrange candidate names in that order. For example, here is one generated alphabet as shown below: DCVUZMYGLQENHOBASWTJIRXFPK Given a list of names: Adams Carter King Ong smith Washington Listed names according to a generated alphabet as shown above: Carter Ong Adams Smith Washington King Assume that a generated alphabet is given as a string (input or a named constant). provide a solution for this problem given a list of names (input from keyboard as string with one name at a time and you can assume that each name starts with a different letter to keep the problem simpler).Explanation / Answer
# Here is the python code for given problem
formated_string = "DCVUZMYGLQENHOBASWTJIRXFPK"
number = int(input("Enter number of persons: "))
persons = []
sorted_array = []
for i in range(0,number):
name = input("Enter person name: ")
persons.append(name);
for i in range(0,len(formated_string)):
for j in persons:
if(j[0]==formated_string[i]):
sorted_array.append(j)
print(sorted_array)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.