Discharge on screen lists of components of different lists



  • Several lists are available at the entrance:

    auto = ['KIA', 'Volkswagen', 'Mitsubishi', 'Renault']
    auto_model1 = ['Cerato', 'Sorento', 'C`eed', 'Carnival']
    auto_model3 = ['Passat', 'Tiguan', 'Golf', 'Touran']
    auto_model2 = ['Galant', 'Pajero', 'Colt', 'Grandis']
    auto_model4 = ['Megan', 'Kaptur', 'Clio', 'C4 Picasso']
    car_body = ['sedan', 'crossover', 'hatchback', 'minivan']
    

    The following should be concluded (example for one mark):

    KIA Cerato --> sedan
    KIA Sorento --> crossover
    KIA C`eed --> hatchback
    KIA Carnival --> minivan
    

    It's important! A newcomers' mission, that's all new.

    1. Only data structures can be used: lists
    2. Not using special libraries and modules.

    I've already broken my head. I don't know how to use the cycles, but not to cross all the elements of the list. Thank you for your help.



  • Is that what it took?

    auto = ['KIA', 'Volkswagen', 'Mitsubishi', 'Renault']
    auto_model1 = ['Cerato', 'Sorento', 'C`eed', 'Carnival']
    auto_model3 = ['Passat', 'Tiguan', 'Golf', 'Touran']
    auto_model2 = ['Galant', 'Pajero', 'Colt', 'Grandis']
    auto_model4 = ['Megan', 'Kaptur', 'Clio', 'C4 Picasso']
    car_body = ['sedan', 'crossover', 'hatchback', 'minivan']
    

    text = "KIA C`eed"

    models = [auto_model1, auto_model2, auto_model3, auto_model4]

    components = text.split()

    index_auto = auto.index(components[0])
    index_model = models[index_auto].index(components[1])

    body = car_body[index_model]

    print(text, "-->", body)

    Well, that's a good check. -1 When the indices are received, insert (situation when the object is not found on the list)


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2