Technical problem
This first line in your for loop doesn't return one price as an integer but the whole price list. This dictionary1["price"] gives you [55, 100, 25].
Logical problem
Data structure
I think you misunderstood how a dictionary work. In your case it seems the best to use a dictionary with a structure where the prices are the values and the names are the keys.
better_dict = {
'a': 55,
'b': 100,
'c': 25}
In the solution code below I transform your dict via dict(zip(...)) into that form.
Iterate over a dictionary
When you iterate over a dictionary with a for loop you only get the keys not the values. In my example you have the keys ['a', 'b', 'c']. When you want to access the values in a dictionary you have to use the key inside the loop.
Solution
This solutions tries to modify your code as less as possible.
#!/usr/bin/python3
dictionary1 = {
"name": ["a", "b", "c"],
"price": [55, 100, 25]
}
# transform your dict into an easier structure
better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}
highest_price = 0
winner = ""
for name in better_dict: # --> ['a', 'b', 'c']
# get the value by key/name
bid_amount = better_dict[name]
if bid_amount > highest_price:
highest_price = bid_amount
winner = name # use the key as name
print(f"the winner is: {winner}. With {highest_price}")
Alternative solution
Here you have an alternative approach without using a for loop. It also uses the transformed data structure.
#!/usr/bin/python3
dictionary1 = {
"name": ["a", "b", "c"],
"price": [55, 100, 25]
}
better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}
# Find key with highest price
winner = sorted(better_dict, key=lambda k: better_dict[k])[-1]
# Get highest price by winners name
highest_price = better_dict[winner]
print(f"the winner is: {winner}. With {highest_price}")
I will try to break down the winner = line for you. sorted(better_dict) (without key=!) would return the keys (names) of the dictionary. But you want the values. So key=lambda k: better_dict[k] tell the sorted() to use the lambda function that returns the value of an element indexed by a key k. Because sorted() use ascending (lowest to highest price) order by default we use the last element of the returned list to get the name with the highest price. You can access the last element of a list via [-1].