-2

I have these three lists:

bankNames = ["bank1","bank2","bank3"]
interestRate = (0.05,0.01,0.08)
namePlusInterest = zip(interestRate,bankNames)

print(max(list(namePlusInterest)))

the print function returns an output of:

(0.08, 'bank3')

I want to be able to split the output into individual variables (for example):

MaxRate = 0.08
MaxBank = 'bank3'

So for later in my code I can say:

print(MaxBank + "has the highest interest rate of" + MaxRate)
kingmic
  • 37
  • 4
  • `zip[interestRate,bankNames]` must be `zip(interestRate,bankNames)`. The result is a tuple. Extract itrs first and second elements. – DYZ Apr 06 '22 at 03:10
  • Does this answer your question? [Getting one value from a tuple](https://stackoverflow.com/questions/3136059/getting-one-value-from-a-tuple) – DYZ Apr 06 '22 at 03:11

1 Answers1

0

You can use tuple unpacking to get each individual element from the tuple:

bankNames = ["bank1", "bank2", "bank3"]
interestRate = (0.05, 0.01, 0.08)

namePlusInterest = zip(interestRate, bankNames)

MaxRate, MaxBank = max(list(namePlusInterest))

print(f"{MaxBank} has the highest interest rate of {MaxRate}")
Dan Constantinescu
  • 1,426
  • 1
  • 7
  • 11