Created a list of flowers
>>> flowers = ['rose','bougainvillea','yucca','marigold','daylilly','lilly of the valley']
Then
I had to assign a list of thorny subscriptions to the flowers list, consisting of the first three objects on the list.
This is what I tried:
>>> thorny = [] >>> thorny = flowers[1-3] >>> thorny 'daylilly' >>> thorny = flowers[0-2] >>> thorny 'daylilly' >>> flowers[0,1,2] Traceback (most recent call last): File "<pyshell#76>", line 1, in <module> flowers[0,1,2] TypeError: list indices must be integers, not tuple >>> thorny = [flowers[0] + ' ,' + flowers[1] + ' ,' + flowers[2]] >>> thorny ['rose ,bougainvillea ,yucca']
How can I get only the first 3 objects from the color list, while preserving the appearance of the list inside the list?
Robert Montz
source share