0
from collections import namedtuple

categories = ['cigarettes', 'snuff', 'cigarillos']
cigarette_brands = ['camel', 'american_spirit']
cigarillo_brands = ['good_times', 'black_and_mild']
snuff_brands = ['grizzly', 'copenhagen', 'kodiak']
cam_cig_flavors = ['blue_king', 'blue_100', 'full_flavor_king', 'full_flavor_100', 'menthol_king', 'menthol_100' 'menthol_gold_king', 'menthol_gold_100', 'non_filter', 'silver_100']

tobacco = namedtuple('Tobacco', categories)
tobacco.cigarettes = namedtuple('Cigarettes', cigarette_brands)
tobacco.snuff = namedtuple('Snuff', snuff_brands)
tobacco.cigarillos = namedtuple('Cigarillos', cigarillo_brands)

tobacco.cigarettes.camel = namedtuple('Camel', cam_cig_flavors)
for flavor cam_cig_flavors:
    tobacco.cigarettes.camel.flavor = '$57.35'

I am trying to set the price of individual flavors using the for loop:

for flavor in cam_cig_flavors:
    tobacco.cigarettes.camel.flavor = '$57.35'

I want to get the following output for print(tobacco.cigarettes.camel.full_flavor_king)

> $57.35

I know it's setting tobacco.cigarettes.camel.flavor equal to $57.35 instead of iterating through flavors. How can I make it iterate through flavors instead? For example, I want it to do the following in each iteration:

tobacco.cigarettes.camel.blue_king = '$57.35'

then,

tobacco.cigarettes.camel.blue_100 = '$57.35'

so on and so forth.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Rehan
  • 9
  • 3

0 Answers0