创建了一个列表花
>>> flowers = ['rose','bougainvillea','yucca','marigold','daylilly','lilly of the valley']
然后,
我不得不分配列表棘手的列表花的子列表,包括列表中的前三个对象.
这是我试过的:
>>> thorny = []
>>> thorny = flowers[1-3]
>>> thorny
'daylilly'
>>> thorny = flowers[0-2]
>>> thorny
'daylilly'
>>> flowers[0,1,2]
Traceback (most recent call last):
File "", line 1, in
flowers[0,1,2]
TypeError: list indices must be integers, not tuple
>>> thorny = [flowers[0] + ' ,' + flowers[1] + ' ,' + flowers[2]]
>>> thorny
['rose ,bougainvillea ,yucca']
如何保持列表花的前3个对象,同时保持列表中列表的外观?