How to remove first and last using python value=A 0006 005C 0078 0030 0034 0046 0030 00
Asked
Active
Viewed 1,427 times
1
-
Presuming that this is a string and you are splitting by white space. – jamylak Jul 13 '12 at 05:45
3 Answers
9
You can use a list slice:
>>> a = ["one", "two", "three", "four"]
>>> a[1:-1]
['two', 'three']
See Good Primer for Python Slice Notation for more details about how this notation works.

Community
- 1
- 1

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
2
from your description it is a bit unclear what "first and last" are in your example. if you mean the first and last "word", eg 'A' and '00' you yould use:
" ".join("A 0006 005C 0078 0030 0034 0046 0030 00".split()[1:-1])
this returns
'0006 005C 0078 0030 0034 0046 0030'

Gryphius
- 75,626
- 6
- 48
- 54
0
value='A 0006 005C 0078 0030 0034 0046 0030 00'
value[1:-2-1]
You will get the result as
' 0006 005C 0078 0030 0034 0046 0030'

Eldho
- 3
- 3