Assignment 5
Assignment 5
1. Nested Lists
Program:
if __name__ == '__main__':
students = []
for _ in range(int(input())):
name = input()
score = float(input())
students.append([name, score])
unique_grades = sorted(set(score for name, score in stud
ents))
second_lowest_grade = unique_grades[1]
second_lowest_students = sorted(name for name, score in
students if score == second_lowest_grade)
for name in second_lowest_students:
print(name)
Program:
def split_and_join(line):
if __name__ == '__main__':
line = input()
result = split_and_join(line)
print(result)
3. Find a string
Program:
count = 0
sub_length = len(sub_string)
for i in range(len(string) - sub_length + 1):
if string[i:i + sub_length] == sub_string:
count += 1
return count
if __name__ == '__main__':
string = input().strip()
sub_string = input().strip()
String Validators
Program:
s = input()
4. Mutation
Program:
if __name__ == '__main__':
s = input()
i, c = input().split()
s_new = mutate_string(s, int(i), c)
print(s_new)