user3583094
user3583094

Reputation: 105

Putting items of a list into another list in Python?

I'm a beginner programmer and I'm trying to make a generator. I'm wondering how to put the items of a list into another list. For example, I would want the items of c1 to be in c3. So then c3 would have the items ['chocolate', 'white chocolate', 'plain', 'sugar']. I would just want to do it without having to type it all out, because I'm adding more things.

import random

c1 = ['chocolate', 'white chocolate']
c2 = ['chips', 'chunks']
c3 = ['plain', 'sugar']

print "A", (random.choice(c3)), "cookie with", (random.choice(c1)), (random.choice(c2))

So, is there anyway I can go about doing this? I know I don't have much so far, but it is growing, and the advice will come useful later.

Upvotes: 0

Views: 499

Answers (1)

citsonga
citsonga

Reputation: 323

Combining lists is easy in Python:

newlist = c1 + c2 + c3

You can add specific items by appending the list:

newlist = []
newlist.append(random.choice(c3))

Upvotes: 1

Related Questions