1

using Python3.5 i have two lists of strings, and i want to 'multiply' the two lists so i can do an ebay search for carparts, and print to the console.

cars = ['ford focus', 'honda civic', 'chevy truck',]
parts = ['ignition', 'head light']

for car in cars:
    for part in parts:
        print(cars[car]) + parts[part])

expected output:

>>>ford focus ignition
ford focus head light
honda civic ignition
honda civic head light
chevy truck ignition
chevy truck head light

Ive tried several different methods, but cant seem to get anything to give me the output i need. i attempted to use numpy, but couldnt figure out how to get it to install. "pip install numpy" at cmd kept giving me some sort of error that i couldnt figure out. i need the output to be both strings on the same line, because i will copy and paste them into a notepad document and utilize the data by the line for an ebay search.

  • i think i would need to know the question and the answer before i can tell you how my question is different. –  Jan 10 '16 at 15:34
  • Use `itertools.product`. And then you can do something as simple as `[' '.join(l) for l in itertools.product(cars, parts)]` to get your result – Chrispresso Jan 10 '16 at 15:35
  • thanks @thefourtheye, but your page shows me how to enumerate my list. i dont need to enumerate the list, what i need is to print a list of car parts for every car. this is simply handling strings. im apologize if i didnt make it clear the first time. –  Jan 10 '16 at 15:45
  • @indianhearts Actually `car` and `part` variables itself will have the actual value, you don't have to index the `cars` and `parts` with them respectively. Simply do `print(car, part)` – thefourtheye Jan 10 '16 at 15:49
  • oh gosh! that was easy as py. i guess i was thinking much too deeply about it, the correct answer was to do like you said: print(car + ' ' + part) tremendous thanks. –  Jan 10 '16 at 15:52

0 Answers0