I have a list containing dictionaries:
base = [
{"name": "Earth", "Density": 5.427},
{"name": "Mars", "Density": 5.513},
{"name": "Venus", "Density": 5.204},
]
name = input("What planet are you looking for? ")
The function should return the index of an item(planet in this case) or -1 if it doesn't exist.
F.e | For input= Earth, expected output would be: 0
For input = venus, expected output: 2
The binary search
is a must-have in this task.
I am not even giving u my code because it do not even work. I know how binary search works, but no idea how to use it in list of dictionaries.
PS. You dont have to write the whole code, just help me how to implement biarny search into list of dictionaries.