= (2,7,4) tuple_example
5 Data structures
In this chapter we’ll learn about the python data structures that are often used or appear while analyzing data.
5.1 Tuple
Tuple is a sequence of python objects, with two key characeterisics: (1) the number of objects are fixed, and (2) the objects are immutable, i.e., they cannot be changed.
Tuple can be defined as a sequence of python objects separated by commas, and enclosed in rounded brackets (). For example, below is a tuple containing three integers.
Tuple can be defined without the rounded brackets as well:
= 2, 7, 4 tuple_example
We can check the data type of a python object using the type() function. Let us check the data type of the object tuple_example.
type(tuple_example)
tuple
Elements of a tuple can be extracted using their index within square brackets. For example the second element of the tuple tuple_example can be extracted as follows:
1] tuple_example[
7
Note that an element of a tuple cannot be modified. For example, consider the following attempt in changing the second element of the tuple tuple_example.
1] = 8 tuple_example[
TypeError: 'tuple' object does not support item assignment
The above code results in an error as tuple elements cannot be modified.
5.1.1 Practice exercise 1
USA’s GDP per capita from 1960 to 2021 is given by the tuple T in the code cell below. The values are arranged in ascending order of the year, i.e., the first value is for 1960, the second value is for 1961, and so on. Print the years in which the GDP per capita of the US increased by more than 10%.
= (3007, 3067, 3244, 3375,3574, 3828, 4146, 4336, 4696, 5032,5234,5609,6094,6726,7226,7801,8592,9453,10565,11674,12575,13976,14434,15544,17121,18237,19071,20039,21417,22857,23889,24342,25419,26387,27695,28691,29968,31459,32854,34515,36330,37134,37998,39490,41725,44123,46302,48050,48570,47195,48651,50066,51784,53291,55124,56763,57867,59915,62805,65095,63028,69288) T
Solution:
#Iterating over each element of the tuple
for i in range(len(T)-1):
#Computing percentage increase in GDP per capita in the (i+1)th year
= (T[i+1]-T[i])/T[i]
increase
#Printing the year if the increase in GDP per capita is more than 10%
if increase>0.1:
print(i+1961)
1973
1976
1977
1978
1979
1981
1984
5.1.2 Concatenating tuples
Tuples can be concatenated using the + operator to produce a longer tuple:
2,7,4) + ("another", "tuple") + ("mixed","datatypes",5) (
(2, 7, 4, 'another', 'tuple', 'mixed', 'datatypes', 5)
Multiplying a tuple by an integer results in repetition of the tuple:
2,7,"hi") * 3 (
(2, 7, 'hi', 2, 7, 'hi', 2, 7, 'hi')
5.1.3 Unpacking tuples
If tuples are assigned to an expression containing multiple variables, the tuple will be unpacked and each variable will be assigned a value as per the order in which it appears. See the example below.
= (4.5, "this is a string", (("Nested tuple",5))) x,y,z
x
4.5
y
'this is a string'
z
('Nested tuple', 5)
If we are interested in retrieving only some values of the tuple, the expression *_ can be used to discard the other values. Let’s say we are interested in retrieving only the first and the last two values of the tuple:
*_,y,z = (4.5, "this is a string", (("Nested tuple",5)),"99",99) x,
x
4.5
y
'99'
z
99
5.1.4 Practice exercise 2
USA’s GDP per capita from 1960 to 2021 is given by the tuple T in the code cell below. The values are arranged in ascending order of the year, i.e., the first value is for 1960, the second value is for 1961, and so on.
Write a function that has two parameters:
- Year : which indicates the year from which the GDP per capita are available in the second parameter
- Tuple of GDP per capita’s: Tuple consisting of GDP per capita for consecutive years starting from the year mentioned in the first parameter.
The function should return a tuple of length two, where the first element of the tuple is the number of years when the increase in GDP per capita was more than 5%, and the second element is the most recent year in which the GDP per capita increase was more than 5%.
Call the function to find the number of years, and the most recent year in which the GDP per capita increased by more than 5%, since the year 2000. Assign the number of years
returned by the function to a variable named num_years
, and assign the most recent year to a variable named recent_year
. Print the values of num_years
and recent_year
.
= (3007, 3067, 3244, 3375,3574, 3828, 4146, 4336, 4696, 5032,5234,5609,6094,6726,7226,7801,8592,9453,10565,11674,12575,13976,14434,15544,17121,18237,19071,20039,21417,22857,23889,24342,25419,26387,27695,28691,29968,31459,32854,34515,36330,37134,37998,39490,41725,44123,46302,48050,48570,47195,48651,50066,51784,53291,55124,56763,57867,59915,62805,65095,63028,69288) T
def gdp_inc(year,gdp_tuple):
=0
countfor i in range(len(gdp_tuple)-1):
#Computing the increase in GDP per capita for the (i+1)th year
= (gdp_tuple[i+1]-gdp_tuple[i])/gdp_tuple[i]
increase if increase>0.05:
print(year+i)
#Over-writing the value of recent_year if the increase in GDP per capita for a more recent year is more than 5%
= year+i+1
recent_year
#Counting the number of years for which the increase in GDP per capita is more than 5%
= count+1
count return((count,recent_year))
= gdp_inc(2000,T[40:])
num_years, recent_year print("Number of years when increase in GDP per capita was more than 5% = ", num_years)
print("The most recent year in which the increase in GDP per capita was more than 5% = ", recent_year)
2003
2004
2020
Number of years when increase in GDP per capita was more than 5% = 3
The most recent year in which the increase in GDP per capita was more than 5% = 2021
5.1.5 Tuple methods
A couple of useful tuple methods are count
, which counts the occurences of an element in the tuple and index
, which returns the position of the first occurance of an element in the tuple:
= (2,5,64,7,2,2) tuple_example
2) tuple_example.count(
3
2) tuple_example.index(
0
Now that we have an idea about tuple, let us try to think where it can be used.
5.2 List
List is a sequence of python objects, with two key characeterisics that differentiates it from tuple: (1) the number of objects are variable, i.e., objects can be added or removed from a list, and (2) the objects are mutable, i.e., they can be changed.
List can be defined as a sequence of python objects separated by commas, and enclosed in square brackets []. For example, below is a list consisting of three integers.
= [2,7,4] list_example
5.2.1 Adding and removing elements in a list
We can add elements at the end of the list using the append method. For example, we append the string ‘red’ to the list list_example below.
'red') list_example.append(
list_example
[2, 7, 4, 'red']
Note that the objects of a list or a tuple can be of different datatypes.
An element can be added at a specific location of the list using the insert method. For example, if we wish to insert the number 2.32 as the second element of the list list_example, we can do it as follows:
1,2.32) list_example.insert(
list_example
[2, 2.32, 7, 4, 'red']
For removing an element from the list, the pop and remove methods may be used. The pop method removes an element at a particular index, while the remove method removes the element’s first occurence in the list by its value. See the examples below.
Let us say, we need to remove the third element of the list.
2) list_example.pop(
7
list_example
[2, 2.32, 4, 'red']
Let us say, we need to remove the element ‘red’.
'red') list_example.remove(
list_example
[2, 2.32, 4]
#If there are multiple occurences of an element in the list, the first occurence will be removed
= [2,3,2,4,4]
list_example2 2)
list_example2.remove( list_example2
[3, 2, 4, 4]
For removing multiple elements in a list, either pop
or remove
can be used in a for
loop, or a for
loop can be used with a condition. See the examples below.
Let’s say we need to remove integers less than 100 from the following list.
= list(range(95,106))
list_example3 list_example3
[95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105]
#Method 1: For loop with remove
= list(list_example3) #
list_example3_filtered for element in list_example3:
if element<100:
list_example3_filtered.remove(element)print(list_example3_filtered)
[100, 101, 102, 103, 104, 105]
\(\color{red}{\text{Q1}}\): What’s the need to define a new variable list\_example3\_filtered
in the above code?
\(\color{blue}{\text{A1}}\): Replace list_example3_filtered with list_example3 and identify the issue.
#Method 2: Check this method after reading Section 5.2.6 on slicing a list
= list(range(95,106))
list_example3
#Slicing a list using ':' creates a copy of the list, and so
for element in list_example3[:]:
if element<100:
list_example3.remove(element)print(list_example3)
[100, 101, 102, 103, 104, 105]
#Method 3: For loop with condition
for element in list_example3 if element>100] [element
[101, 102, 103, 104, 105]
5.2.2 List comprehensions
List comprehension is a compact way to create new lists based on elements of an existing list or other objects.
Example: Create a list that has squares of natural numbers from 5 to 15.
= [(x**2) for x in range(5,16)]
sqrt_natural_no_5_15 print(sqrt_natural_no_5_15)
[25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]
Example: Create a list of tuples, where each tuple consists of a natural number and its square, for natural numbers ranging from 5 to 15.
= [(x,x**2) for x in range(5,16)]
sqrt_natural_no_5_15 print(sqrt_natural_no_5_15)
[(5, 25), (6, 36), (7, 49), (8, 64), (9, 81), (10, 100), (11, 121), (12, 144), (13, 169), (14, 196), (15, 225)]
5.2.3 Practice exercise 3
Below is a list consisting of responses to the question: “At what age do you think you will marry?” from students of the STAT303-1 Fall 2022 class.
=['24','30','28','29','30','27','26','28','30+','26','28','30','30','30','probably never','30','25','25','30','28','30+ ','30','25','28','28','25','25','27','28','30','30','35','26','28','27','27','30','25','30','26','32','27','26','27','26','28','37','28','28','28','35','28','27','28','26','28','26','30','27','30','28','25','26','28','35','29','27','27','30','24','25','29','27','33','30','30','25','26','30','32','26','30','30','I wont','25','27','27','25','27','27','32','26','25','never','28','33','28','35','25','30','29','30','31','28','28','30','40','30','28','30','27','by 30','28','27','28','30-35','35','30','30','never','30','35','28','31','30','27','33','32','27','27','26','N/A','25','26','29','28','34','26','24','28','30','120','25','33','27','28','32','30','26','30','30','28','27','27','27','27','27','27','28','30','30','30','28','30','28','30','30','28','28','30','27','30','28','25','never','69','28','28','33','30','28','28','26','30','26','27','30','25','Never','27','27','25'] exp_marriage_age
Use list comprehension to:
5.2.3.1
Remove the elements that are not integers - such as ‘probably never’, ‘30+’, etc. What is the length of the new list?
Hint: The built-in python function of the str
class - isdigit() may be useful to check if the string contains only digits.
= [x for x in exp_marriage_age if x.isdigit()==True]
exp_marriage_age_num print("Length of the new list = ",len(exp_marriage_age_num))
Length of the new list = 181
5.2.3.2
Cap the values greater than 80 to 80, in the clean list obtained in (1). What is the mean age when people expect to marry in the new list?
= [min(int(x),80) for x in exp_marriage_age_num]
exp_marriage_age_capped print("Mean age when people expect to marry = ", sum(exp_marriage_age_capped)/len(exp_marriage_age_capped))
Mean age when people expect to marry = 28.955801104972377
5.2.3.3
Determine the percentage of people who expect to marry at an age of 30 or more.
print("Percentage of people who expect to marry at an age of 30 or more =", str(100*sum([1 for x in exp_marriage_age_capped if x>=30])/len(exp_marriage_age_capped)),"%")
Percentage of people who expect to marry at an age of 30 or more = 37.01657458563536 %
5.2.4 Concatenating lists
As in tuples, lists can be concatenated using the + operator:
import time as tm
= [5,'hi',4]
list_example4 = list_example4 + [None,'7',9]
list_example4 list_example4
[5, 'hi', 4, None, '7', 9]
For adding elements to a list, the extend
method is preferred over the +
operator. This is because the +
operator creates a new list, while the extend
method adds elements to an existing list. Thus, the extend
operator is more memory efficient.
= [5,'hi',4]
list_example4 None, '7', 9])
list_example4.extend([ list_example4
[5, 'hi', 4, None, '7', 9]
5.2.5 Sorting a list
A list can be sorted using the sort
method:
= [6,78,9]
list_example5 =True) #the reverse argument is used to specify if the sorting is in ascending or descending order
list_example5.sort(reverse list_example5
[78, 9, 6]
5.2.6 Slicing a list
We may extract or update a section of the list by passing the starting index (say start
) and the stopping index (say stop
) as start:stop
to the index operator []. This is called slicing a list. For example, see the following example.
= [4,7,3,5,7,1,5,87,5] list_example6
Let us extract a slice containing all the elements from the the 3rd position to the 7th position.
2:7] list_example6[
[3, 5, 7, 1, 5]
Note that while the element at the start
index is included, the element with the stop
index is excluded in the above slice.
If either the start
or stop
index is not mentioned, the slicing will be done from the beginning or until the end of the list, respectively.
7] list_example6[:
[4, 7, 3, 5, 7, 1, 5]
2:] list_example6[
[3, 5, 7, 1, 5, 87, 5]
To slice the list relative to the end, we can use negative indices:
-4:] list_example6[
[1, 5, 87, 5]
-4:-2:] list_example6[
[1, 5]
An extra colon (‘:’) can be used to slice every ith element of a list.
#Selecting every 3rd element of a list
3] list_example6[::
[4, 5, 5]
#Selecting every 3rd element of a list from the end
-3] list_example6[::
[5, 1, 3]
#Selecting every element of a list from the end or reversing a list
-1] list_example6[::
[5, 87, 5, 1, 7, 5, 3, 7, 4]
5.2.7 Practice exercise 4
Start with the list [8,9,10]. Do the following:
5.2.7.1
Set the second entry (index 1) to 17
= [8,9,10]
L 1]=17 L[
5.2.7.2
Add 4, 5, and 6 to the end of the list
= L+[4,5,6] L
5.2.7.3
Remove the first entry from the list
0) L.pop(
8
5.2.7.4
Sort the list
L.sort()
5.2.7.5
Double the list (concatenate the list to itself)
=L+L L
5.2.7.6
Insert 25 at index 3
The final list should equal [4,5,6,25,10,17,4,5,6,10,17]
3,25)
L.insert( L
[4, 5, 6, 25, 10, 17, 4, 5, 6, 10, 17]
Now that we have an idea about lists, let us try to think where it can be used.
Now that we have learned about lists and tuples, let us compare them.
\(\color{red}{\text{Q2}}\): A list seems to be much more flexible than tuple, and can replace a tuple almost everywhere. Then why use tuple at all?
\(\color{blue}{\text{A2}}\): The additional flexibility of a list comes at the cost of efficiency. Some of the advatages of a tuple over a list are as follows:
Since a list can be extended, space is over-allocated when creating a list. A tuple takes less storage space as compared to a list of the same length.
Tuples are not copied. If a tuple is assigned to another tuple, both tuples point to the same memory location. However, if a list is assigned to another list, a new list is created consuming the same memory space as the orignial list.
Tuples refer to their element directly, while in a list, there is an extra layer of pointers that refers to their elements. Thus it is faster to retrieve elements from a tuple.
The examples below illustrate the above advantages of a tuple.
#Example showing tuples take less storage space than lists for the same elements
= (1, 2, 'Obama')
tuple_ex = [1, 2, 'Obama']
list_ex print("Space taken by tuple =",tuple_ex.__sizeof__()," bytes")
print("Space taken by list =",list_ex.__sizeof__()," bytes")
Space taken by tuple = 48 bytes
Space taken by list = 64 bytes
#Examples showing that a tuples are not copied, while lists can be copied
= tuple(tuple_ex)
tuple_copy print("Is tuple_copy same as tuple_ex?", tuple_ex is tuple_copy)
= list(list_ex)
list_copy print("Is list_copy same as list_ex?",list_ex is list_copy)
Is tuple_copy same as tuple_ex? True
Is list_copy same as list_ex? False
#Examples showing tuples takes lesser time to retrieve elements
import time as tm
= tm.time()
tt = list(range(1000000)) #List containinig whole numbers upto 1 million
list_ex =(list_ex[::-2])
aprint("Time take to retrieve every 2nd element from a list = ", tm.time()-tt)
= tm.time()
tt = tuple(range(1000000)) #tuple containinig whole numbers upto 1 million
tuple_ex =(tuple_ex[::-2])
aprint("Time take to retrieve every 2nd element from a tuple = ", tm.time()-tt)
Time take to retrieve every 2nd element from a list = 0.03579902648925781
Time take to retrieve every 2nd element from a tuple = 0.02684164047241211
5.3 Dictionary
A dictionary consists of key-value pairs, where the keys and values are python objects. While values can be any python object, keys need to be immutable python objects, like strings, integers, tuples, etc. Thus, a list can be a value, but not a key, as elements of list can be changed. A dictionary is defined using the keyword dict
along with curly braces, colons to separate keys and values, and commas to separate elements of a dictionary:
= {'USA':'Joe Biden', 'India':'Narendra Modi', 'China':'Xi Jinping'} dict_example
Elements of a dictionary can be retrieved by using the corresponding key.
'India'] dict_example[
'Narendra Modi'
5.3.1 Adding and removing elements in a dictionary
New elements can be added to a dictionary by defining a key in square brackets and assiging it to a value:
'Japan'] = 'Fumio Kishida'
dict_example['Countries'] = 4
dict_example[ dict_example
{'USA': 'Joe Biden',
'India': 'Narendra Modi',
'China': 'Xi Jinping',
'Japan': 'Fumio Kishida',
'Countries': 4}
Elements can be removed from the dictionary using the del
method or the pop
method:
#Removing the element having key as 'Countries'
del dict_example['Countries']
dict_example
{'USA': 'Joe Biden',
'India': 'Narendra Modi',
'China': 'Xi Jinping',
'Japan': 'Fumio Kishida'}
#Removing the element having key as 'USA'
'USA') dict_example.pop(
'Joe Biden'
dict_example
{'India': 'Narendra Modi', 'China': 'Xi Jinping', 'Japan': 'Fumio Kishida'}
New elements can be added, and values of exisiting keys can be changed using the update
method:
= {'USA':'Joe Biden', 'India':'Narendra Modi', 'China':'Xi Jinping','Countries':3}
dict_example dict_example
{'USA': 'Joe Biden',
'India': 'Narendra Modi',
'China': 'Xi Jinping',
'Countries': 3}
'Countries':4, 'Japan':'Fumio Kishida'}) dict_example.update({
dict_example
{'USA': 'Joe Biden',
'India': 'Narendra Modi',
'China': 'Xi Jinping',
'Countries': 4,
'Japan': 'Fumio Kishida'}
5.3.2 Iterating over elements of a dictionary
The items() attribute of a dictionary can be used to iterate over elements of a dictionary.
for key,value in dict_example.items():
print("The Head of State of",key,"is",value)
The Head of State of USA is Joe Biden
The Head of State of India is Narendra Modi
The Head of State of China is Xi Jinping
The Head of State of Countries is 4
The Head of State of Japan is Fumio Kishida
5.3.3 Practice exercise 5
The GDP per capita of USA for most years from 1960 to 2021 is given by the dictionary D
given in the code cell below.
Find:
- The GDP per capita in 2015
- The GDP per capita of 2014 is missing. Update the dictionary to include the GDP per capita of 2014 as the average of the GDP per capita of 2013 and 2015.
- Impute the GDP per capita of other missing years in the same manner as in (2), i.e., as the average GDP per capita of the previous year and the next year. Note that the GDP per capita is not missing for any two consecutive years.
- Print the years and the imputed GDP per capita for the years having a missing value of GDP per capita in (3).
= {'1960':3007,'1961':3067,'1962':3244,'1963':3375,'1964':3574,'1965':3828,'1966':4146,'1967':4336,'1968':4696,'1970':5234,'1971':5609,'1972':6094,'1973':6726,'1974':7226,'1975':7801,'1976':8592,'1978':10565,'1979':11674, '1980':12575,'1981':13976,'1982':14434,'1983':15544,'1984':17121,'1985':18237, '1986':19071,'1987':20039,'1988':21417,'1989':22857,'1990':23889,'1991':24342, '1992':25419,'1993':26387,'1994':27695,'1995':28691,'1996':29968,'1997':31459, '1998':32854,'2000':36330,'2001':37134,'2002':37998,'2003':39490,'2004':41725, '2005':44123,'2006':46302,'2007':48050,'2008':48570,'2009':47195,'2010':48651, '2011':50066,'2012':51784,'2013':53291,'2015':56763,'2016':57867,'2017':59915,'2018':62805, '2019':65095,'2020':63028,'2021':69288} D
Solution:
print("GDP per capita in 2015 =", D['2015'])
'2014'] = (D['2013']+D['2015'])/2
D[
#Iterating over all years from 1960 to 2021
for i in range(1960,2021):
#Imputing the GDP of the year if it is missing
if str(i) not in D.keys():
str(i)] = (D[str(i-1)]+D[str(i+1)])/2
D[print("Imputed GDP per capita for the year",i,"is $",D[str(i)])
GDP per capita in 2015 = 56763
Imputed GDP per capita for the year 1969 is $ 4965.0
Imputed GDP per capita for the year 1977 is $ 9578.5
Imputed GDP per capita for the year 1999 is $ 34592.0
5.3.4 Practice exercise 6
The object deck
defined below corresponds to a deck of cards. Estimate the probablity that a five card hand will be a flush, as follows:
- Write a function that accepts a hand of 5 cards as argument, and returns whether the hand is a flush or not.
- Randomly pull a hand of 5 cards from the deck. Call the function developed in (1) to determine if the hand is a flush.
- Repeat (2) 10,000 times.
- Estimate the probability of the hand being a flush from the results of the 10,000 simulations.
You may use the function shuffle() from the random
library to shuffle the deck everytime before pulling a hand of 5 cards.
= [{'value':i, 'suit':c}
deck for c in ['spades', 'clubs', 'hearts', 'diamonds']
for i in range(2,15)]
Solution:
import random as rm
#Function to check if a 5-card hand is a flush
def chck_flush(hands):
#Assuming that the hand is a flush, before checking the cards
=1
yes_flush
#Storing the suit of the first card in 'first_suit'
= hands[0]['suit']
first_suit
#Iterating over the remaining 4 cards of the hand
for j in range(1,len(hands)):
#If the suit of any of the cards does not match the suit of the first card, the hand is not a flush
if first_suit!=hands[j]['suit']:
= 0;
yes_flush
#As soon as a card with a different suit is found, the hand is not a flush and there is no need to check other cards. So, we 'break' out of the loop
break;
return yes_flush
=0
flushfor i in range(10000):
#Shuffling the deck
rm.shuffle(deck)
#Picking out the first 5 cards of the deck as a hand and checking if they are a flush
#If the hand is a flush it is counted
=flush+chck_flush(deck[0:5])
flush
print("Probability of obtaining a flush=", 100*(flush/10000),"%")
Probability of obtaining a flush= 0.2 %
5.4 Practice exercise 7
The code cell below defines an object having the nutrition information of drinks in starbucks. Assume that the manner in which the information is structured is consistent throughout the object.
={'Cool Lime Starbucks Refreshers™ Beverage': [{'Nutrition_type': 'Calories', 'value': 45}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 11}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Strawberry Acai Starbucks Refreshers™ Beverage': [{'Nutrition_type': 'Calories', 'value': 80}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 18}, {'Nutrition_type': 'Fiber', 'value': 1}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Very Berry Hibiscus Starbucks Refreshers™ Beverage': [{'Nutrition_type': 'Calories', 'value': 60}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 14}, {'Nutrition_type': 'Fiber', 'value': 1}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Evolution Fresh™ Organic Ginger Limeade': [{'Nutrition_type': 'Calories', 'value': 110}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 28}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Iced Coffee': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Iced Espresso Classics - Vanilla Latte': [{'Nutrition_type': 'Calories', 'value': 130}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 21}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 5}, {'Nutrition_type': 'Sodium', 'value': 65}], 'Iced Espresso Classics - Caffe Mocha': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 23}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 5}, {'Nutrition_type': 'Sodium', 'value': 90}], 'Iced Espresso Classics - Caramel Macchiato': [{'Nutrition_type': 'Calories', 'value': 130}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 21}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 5}, {'Nutrition_type': 'Sodium', 'value': 65}], 'Shaken Sweet Tea': [{'Nutrition_type': 'Calories', 'value': 80}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 19}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Berry Blossom White': [{'Nutrition_type': 'Calories', 'value': 60}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 15}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Black Mango': [{'Nutrition_type': 'Calories', 'value': 150}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 38}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 15}], 'Tazo® Bottled Black with Lemon': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Brambleberry': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 15}], 'Tazo® Bottled Giant Peach': [{'Nutrition_type': 'Calories', 'value': 150}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 37}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 15}], 'Tazo® Bottled Iced Passion': [{'Nutrition_type': 'Calories', 'value': 70}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 17}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Lemon Ginger': [{'Nutrition_type': 'Calories', 'value': 120}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 31}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Organic Black Lemonade': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Organic Iced Black Tea': [{'Nutrition_type': 'Calories', 'value': 60}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 15}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Organic Iced Green Tea': [{'Nutrition_type': 'Calories', 'value': 120}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 31}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Plum Pomegranate': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Tazo® Bottled Tazoberry': [{'Nutrition_type': 'Calories', 'value': 150}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 38}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 15}], 'Tazo® Bottled White Cranberry': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Teavana® Shaken Iced Black Tea': [{'Nutrition_type': 'Calories', 'value': 30}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 8}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Teavana® Shaken Iced Black Tea Lemonade': [{'Nutrition_type': 'Calories', 'value': 70}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 17}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Teavana® Shaken Iced Green Tea': [{'Nutrition_type': 'Calories', 'value': 30}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 8}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Teavana® Shaken Iced Green Tea Lemonade': [{'Nutrition_type': 'Calories', 'value': 70}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 17}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Teavana® Shaken Iced Passion Tango™ Tea': [{'Nutrition_type': 'Calories', 'value': 30}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 8}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 5}], 'Teavana® Shaken Iced Passion Tango™ Tea Lemonade': [{'Nutrition_type': 'Calories', 'value': 90}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 24}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Teavana® Shaken Iced Peach Green Tea': [{'Nutrition_type': 'Calories', 'value': 60}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 15}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Starbucks Refreshers™ Raspberry Pomegranate': [{'Nutrition_type': 'Calories', 'value': 90}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 27}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Starbucks Refreshers™ Strawberry Lemonade': [{'Nutrition_type': 'Calories', 'value': 90}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 27}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Starbucks® Doubleshot Protein Dark Chocolate': [{'Nutrition_type': 'Calories', 'value': 210}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 33}, {'Nutrition_type': 'Fiber', 'value': 2}, {'Nutrition_type': 'Protein', 'value': 20}, {'Nutrition_type': 'Sodium', 'value': 115}], 'Starbucks® Doubleshot Protein Vanilla': [{'Nutrition_type': 'Calories', 'value': 200}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 34}, {'Nutrition_type': 'Fiber', 'value': 2}, {'Nutrition_type': 'Protein', 'value': 20}, {'Nutrition_type': 'Sodium', 'value': 120}], 'Starbucks® Iced Coffee Caramel': [{'Nutrition_type': 'Calories', 'value': 60}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 13}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Starbucks® Iced Coffee Light Sweetened': [{'Nutrition_type': 'Calories', 'value': 50}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 11}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Starbucks® Iced Coffee Unsweetened': [{'Nutrition_type': 'Calories', 'value': 10}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 2}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Blonde Roast': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Clover® Brewed Coffee': [{'Nutrition_type': 'Calories', 'value': 10}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Decaf Pike Place® Roast': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Featured Dark Roast': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Nariño 70 Cold Brew': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 15}], 'Nariño 70 Cold Brew with Milk': [{'Nutrition_type': 'Calories', 'value': 0}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Nitro Cold Brew': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 0}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Nitro Cold Brew with Sweet Cream': [{'Nutrition_type': 'Calories', 'value': 70}, {'Nutrition_type': 'Fat', 'value': 5.0}, {'Nutrition_type': 'Carb', 'value': 5}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 20}], 'Pike Place® Roast': [{'Nutrition_type': 'Calories', 'value': 5}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 0}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 10}], 'Vanilla Sweet Cream Cold Brew': [{'Nutrition_type': 'Calories', 'value': 110}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 14}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 1}, {'Nutrition_type': 'Sodium', 'value': 25}], 'Hot Chocolate': [{'Nutrition_type': 'Calories', 'value': 320}, {'Nutrition_type': 'Fat', 'value': 9.0}, {'Nutrition_type': 'Carb', 'value': 47}, {'Nutrition_type': 'Fiber', 'value': 4}, {'Nutrition_type': 'Protein', 'value': 14}, {'Nutrition_type': 'Sodium', 'value': 160}], 'Starbucks® Signature Hot Chocolate': [{'Nutrition_type': 'Calories', 'value': 430}, {'Nutrition_type': 'Fat', 'value': 26.0}, {'Nutrition_type': 'Carb', 'value': 45}, {'Nutrition_type': 'Fiber', 'value': 5}, {'Nutrition_type': 'Protein', 'value': 12}, {'Nutrition_type': 'Sodium', 'value': 115}], 'Caffè Latte': [{'Nutrition_type': 'Calories', 'value': 190}, {'Nutrition_type': 'Fat', 'value': 7.0}, {'Nutrition_type': 'Carb', 'value': 19}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 13}, {'Nutrition_type': 'Sodium', 'value': 170}], 'Caffè Mocha': [{'Nutrition_type': 'Calories', 'value': 290}, {'Nutrition_type': 'Fat', 'value': 8.0}, {'Nutrition_type': 'Carb', 'value': 42}, {'Nutrition_type': 'Fiber', 'value': 4}, {'Nutrition_type': 'Protein', 'value': 13}, {'Nutrition_type': 'Sodium', 'value': 140}], 'Cappuccino': [{'Nutrition_type': 'Calories', 'value': 120}, {'Nutrition_type': 'Fat', 'value': 4.0}, {'Nutrition_type': 'Carb', 'value': 12}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 8}, {'Nutrition_type': 'Sodium', 'value': 100}], 'Caramel Macchiato': [{'Nutrition_type': 'Calories', 'value': 250}, {'Nutrition_type': 'Fat', 'value': 7.0}, {'Nutrition_type': 'Carb', 'value': 35}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 10}, {'Nutrition_type': 'Sodium', 'value': 150}], 'Cinnamon Dolce Latte': [{'Nutrition_type': 'Calories', 'value': 260}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 40}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 11}, {'Nutrition_type': 'Sodium', 'value': 150}], 'Coconutmilk Mocha Macchiato': [{'Nutrition_type': 'Calories', 'value': 250}, {'Nutrition_type': 'Fat', 'value': 9.0}, {'Nutrition_type': 'Carb', 'value': 32}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 12}, {'Nutrition_type': 'Sodium', 'value': 180}], 'Flat White': [{'Nutrition_type': 'Calories', 'value': 180}, {'Nutrition_type': 'Fat', 'value': 7.0}, {'Nutrition_type': 'Carb', 'value': 18}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 12}, {'Nutrition_type': 'Sodium', 'value': 160}], 'Iced Caffè Latte': [{'Nutrition_type': 'Calories', 'value': 130}, {'Nutrition_type': 'Fat', 'value': 4.5}, {'Nutrition_type': 'Carb', 'value': 13}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 8}, {'Nutrition_type': 'Sodium', 'value': 115}], 'Iced Caffè Mocha': [{'Nutrition_type': 'Calories', 'value': 230}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 36}, {'Nutrition_type': 'Fiber', 'value': 4}, {'Nutrition_type': 'Protein', 'value': 9}, {'Nutrition_type': 'Sodium', 'value': 90}], 'Iced Caramel Macchiato': [{'Nutrition_type': 'Calories', 'value': 250}, {'Nutrition_type': 'Fat', 'value': 7.0}, {'Nutrition_type': 'Carb', 'value': 37}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 10}, {'Nutrition_type': 'Sodium', 'value': 150}], 'Iced Cinnamon Dolce Latte': [{'Nutrition_type': 'Calories', 'value': 200}, {'Nutrition_type': 'Fat', 'value': 4.0}, {'Nutrition_type': 'Carb', 'value': 34}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 7}, {'Nutrition_type': 'Sodium', 'value': 95}], 'Iced Coconutmilk Mocha Macchiato': [{'Nutrition_type': 'Calories', 'value': 260}, {'Nutrition_type': 'Fat', 'value': 9.0}, {'Nutrition_type': 'Carb', 'value': 34}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 11}, {'Nutrition_type': 'Sodium', 'value': 180}], 'Iced Vanilla Latte': [{'Nutrition_type': 'Calories', 'value': 190}, {'Nutrition_type': 'Fat', 'value': 4.0}, {'Nutrition_type': 'Carb', 'value': 30}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 7}, {'Nutrition_type': 'Sodium', 'value': 100}], 'Iced White Chocolate Mocha': [{'Nutrition_type': 'Calories', 'value': 300}, {'Nutrition_type': 'Fat', 'value': 8.0}, {'Nutrition_type': 'Carb', 'value': 47}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 10}, {'Nutrition_type': 'Sodium', 'value': 190}], 'Latte Macchiato': [{'Nutrition_type': 'Calories', 'value': 190}, {'Nutrition_type': 'Fat', 'value': 7.0}, {'Nutrition_type': 'Carb', 'value': 19}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 12}, {'Nutrition_type': 'Sodium', 'value': 160}], 'Starbucks Doubleshot® on Ice Beverage': [{'Nutrition_type': 'Calories', 'value': 45}, {'Nutrition_type': 'Fat', 'value': 1.0}, {'Nutrition_type': 'Carb', 'value': 5}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 3}, {'Nutrition_type': 'Sodium', 'value': 40}], 'Vanilla Latte': [{'Nutrition_type': 'Calories', 'value': 250}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 37}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 12}, {'Nutrition_type': 'Sodium', 'value': 150}], 'White Chocolate Mocha': [{'Nutrition_type': 'Calories', 'value': 360}, {'Nutrition_type': 'Fat', 'value': 11.0}, {'Nutrition_type': 'Carb', 'value': 53}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 14}, {'Nutrition_type': 'Sodium', 'value': 240}], 'Cinnamon Dolce Frappuccino® Blended Coffee': [{'Nutrition_type': 'Calories', 'value': 350}, {'Nutrition_type': 'Fat', 'value': 4.5}, {'Nutrition_type': 'Carb', 'value': 64}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 15}, {'Nutrition_type': 'Sodium', 'value': 0}], 'Coffee Light Frappuccino® Blended Coffee': [{'Nutrition_type': 'Calories', 'value': 110}, {'Nutrition_type': 'Fat', 'value': 0.0}, {'Nutrition_type': 'Carb', 'value': 24}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 3}, {'Nutrition_type': 'Sodium', 'value': 200}], 'Mocha Frappuccino® Blended Coffee': [{'Nutrition_type': 'Calories', 'value': 280}, {'Nutrition_type': 'Fat', 'value': 2.5}, {'Nutrition_type': 'Carb', 'value': 60}, {'Nutrition_type': 'Fiber', 'value': 2}, {'Nutrition_type': 'Protein', 'value': 4}, {'Nutrition_type': 'Sodium', 'value': 220}], 'Mocha Light Frappuccino® Blended Coffee': [{'Nutrition_type': 'Calories', 'value': 140}, {'Nutrition_type': 'Fat', 'value': 0.5}, {'Nutrition_type': 'Carb', 'value': 28}, {'Nutrition_type': 'Fiber', 'value': 1}, {'Nutrition_type': 'Protein', 'value': 4}, {'Nutrition_type': 'Sodium', 'value': 180}], 'Cinnamon Dolce Crème': [{'Nutrition_type': 'Calories', 'value': 200}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 28}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 10}, {'Nutrition_type': 'Sodium', 'value': 135}], 'Vanilla Crème': [{'Nutrition_type': 'Calories', 'value': 200}, {'Nutrition_type': 'Fat', 'value': 6.0}, {'Nutrition_type': 'Carb', 'value': 28}, {'Nutrition_type': 'Fiber', 'value': 0}, {'Nutrition_type': 'Protein', 'value': 10}, {'Nutrition_type': 'Sodium', 'value': 135}], 'Chocolate Smoothie': [{'Nutrition_type': 'Calories', 'value': 320}, {'Nutrition_type': 'Fat', 'value': 5.0}, {'Nutrition_type': 'Carb', 'value': 53}, {'Nutrition_type': 'Fiber', 'value': 8}, {'Nutrition_type': 'Protein', 'value': 20}, {'Nutrition_type': 'Sodium', 'value': 170}], 'Strawberry Smoothie': [{'Nutrition_type': 'Calories', 'value': 300}, {'Nutrition_type': 'Fat', 'value': 2.0}, {'Nutrition_type': 'Carb', 'value': 60}, {'Nutrition_type': 'Fiber', 'value': 7}, {'Nutrition_type': 'Protein', 'value': 16}, {'Nutrition_type': 'Sodium', 'value': 130}]} starbucks_drinks_nutrition
Use the object above to answer the following questions:
5.4.1
What is the datatype of the object?
print("Datatype=",type(starbucks_drinks_nutrition))
Datatype= <class 'dict'>
5.4.1.1
If the object in (1) is a dictionary, what is the datatype of the values of the dictionary?
print("Datatype=",type(starbucks_drinks_nutrition[list(starbucks_drinks_nutrition.keys())[0]]))
Datatype= <class 'list'>
5.4.1.2
If the object in (1) is a dictionary, what is the datatype of the elements within the values of the dictionary?
print("Datatype=",type(starbucks_drinks_nutrition[list(starbucks_drinks_nutrition.keys())[0]][0]))
Datatype= <class 'dict'>
5.4.1.3
How many calories are there in Iced Coffee
?
print("Calories = ",starbucks_drinks_nutrition['Iced Coffee'][0]['value'])
Calories = 5
5.4.1.4
Which drink(s) have the highest amount of protein in them, and what is that protein amount?
#Defining an empty dictionary that will be used to store the protein of each drink
={}
protein
for key,value in starbucks_drinks_nutrition.items():
for nutrition in value:
if nutrition['Nutrition_type']=='Protein':
=(nutrition['value'])
protein[key]
#Using dictionary comprehension to find the key-value pair having the maximum value in the dictionary
for key, value in protein.items() if value == max(protein.values())} {key:value
{'Starbucks® Doubleshot Protein Dark Chocolate': 20,
'Starbucks® Doubleshot Protein Vanilla': 20,
'Chocolate Smoothie': 20}
5.4.1.5
Which drink(s) have a fat content of more than 10g, and what is their fat content?
#Defining an empty dictionary that will be used to store the fat of each drink
={}
fatfor key,value in starbucks_drinks_nutrition.items():
for nutrition in value:
if nutrition['Nutrition_type']=='Fat':
=(nutrition['value'])
fat[key]
#Using dictionary comprehension to find the key-value pair having the value more than 10
for key, value in fat.items() if value>=10} {key:value
{'Starbucks® Signature Hot Chocolate': 26.0, 'White Chocolate Mocha': 11.0}