There are some problems with your code, but it is very simple to solve. I will try to explain well.
First let’s look at the form of the dictionary you created.
a = dict()
a['A'] = sample(range(0, 200), 50)
Printing your dictionary we see that it has only one 'A' key whose value is the list of random numbers created with the sample:
>>> print(a)
>>> {'A': [163, 126, 71, 15, 51, 120, 80, 182, 67, 169, 64, 161, 72, 21, 11, 118, 198, 134, 45, 141, 63, 199, 176, 168, 106, 65, 103, 123, 79, 1, 87, 159, 160, 155, 184, 151, 181, 99, 128, 111, 186, 101, 68, 75, 36, 147, 13, 50, 10, 135]}
When printing the dictionary values we have the result below. Note that the value is a list within a list with the values.
>>> print(a.values())
>>> dict_values([[163, 126, 71, 15, 51, 120, 80, 182, 67, 169, 64, 161, 72, 21, 11, 118, 198, 134, 45, 141, 63, 199, 176, 168, 106, 65, 103, 123, 79, 1, 87, 159, 160, 155, 184, 151, 181, 99, 128, 111, 186, 101, 68, 75, 36, 147, 13, 50, 10, 135]])
Now that we understand the structure of the dictionary it is easier to work. The code below brings the correct result.
for value in a.values():
maior = value[0] # Assuma que o primeiro valor é o maior e compare com os outros
for x in value: # Nesse laço todos os valores vão ser comparados
if x > maior:
maior = x
print(f'O maior valor do dicionário é {maior}')
Alternative code
We can simply use the function max()
:
a = dict()
a['A'] = sample(range(0, 200), 50)
values = a['A']
maior = max(values)
print(f'O maior valor do dicionário é {maior}')