There is a list of dictionaries
list_dict1 = [{'name': 'Valera', 'age': 29}, {'name': 'Bob', 'age': 24}, {'name': 'Boris', 'age': 19}, {'name': 'Natasha', 'age': 27}, {'name': 'Kate', 'age': 32}] The task consists in the following: It is necessary to sort the list by the value of the key “extension”, without using the built-in functions, I tried to do it using the bubble method as follows:
ages = [(x['age']) for x in list_dict1] for num1 in range(0, len(ages)): for num2 in range(0, len(ages)-num1-1): if int(ages[num2]) > int(ages[num2+1]): list_dict1[num2], list_dict1[num2+1] = list_dict1[num2+1], list_dict1[num2] print(list_dict1) the result is not correct:
[{'age': 24, 'name': 'Bob'}, {'age': 29, 'name': 'Valera'}, {'age': 19, 'name': 'Boris'}, {'age': 27, 'name': 'Natasha'}, {'age': 32, 'name': 'Kate'}] Tell me what my mistake is, I will be grateful for any help. Thank you. Sincerely, V.S.V.