Skip to content
Advertisement

How to extract value from tuple of tuples

I have list of this sort. It is the order list of a person:

JavaScript

How do I extract the string and the float value separately? I need to calculate the total order cost based on the given fruit prices:

JavaScript

This is what I have tried:

JavaScript

This yields wrong answer. What am I doing wrong? How can I fix this?

Thanks!

Advertisement

Answer

You might use unpacking together with for loop to get easy to read code, for example

JavaScript

Note , inside forin so name values become 1st element of tuple and qty becomes 2nd element of tuple.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement