I have a list y[color=blue][color=green][color=darkred]
>>>y[/color][/color][/color]
['20001201', 'ARRO', '04276410', '18.500', '19.500', '18.500',
'19.500', '224']
from which I want to extract only the 2nd and 4th item by partially
unpacking the list. So I tried[color=blue][color=green][color=darkred]
>>>a,b = y[2,4][/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: list indices must be integers
Out of curiosity, I tried[color=blue][color=green][color=darkred]
>>>a,b = y[2:4]
>>>a[/color][/color][/color]
'04276410'[color=blue][color=green][color=darkred]
>>> b[/color][/color][/color]
'18.500'
Why does this work (to a point - it gives me items 2 and 3, not 2 and
4 as I require) and not my first attempt? What is the right syntax to
use when partially upacking a sequence?
Thanks in advance
Thomas Philips
>>>y[/color][/color][/color]
['20001201', 'ARRO', '04276410', '18.500', '19.500', '18.500',
'19.500', '224']
from which I want to extract only the 2nd and 4th item by partially
unpacking the list. So I tried[color=blue][color=green][color=darkred]
>>>a,b = y[2,4][/color][/color][/color]
Traceback (most recent call last):
File "<interacti ve input>", line 1, in ?
TypeError: list indices must be integers
Out of curiosity, I tried[color=blue][color=green][color=darkred]
>>>a,b = y[2:4]
>>>a[/color][/color][/color]
'04276410'[color=blue][color=green][color=darkred]
>>> b[/color][/color][/color]
'18.500'
Why does this work (to a point - it gives me items 2 and 3, not 2 and
4 as I require) and not my first attempt? What is the right syntax to
use when partially upacking a sequence?
Thanks in advance
Thomas Philips
Comment