That is not list of elements any type I know.
pyTony
pyMod
6,331 posts since Apr 2010
Reputation Points: 879
Solved Threads: 990
Skill Endorsements: 27
It might be safer to extract the numeric value ...
list1= ['NNW 30', 'SE 15', 'SSW 60', 'NNE 70', 'N 10']
list2 = []
for item in list1:
s = ""
for c in item:
# extract numeric value
if c in '1234567890.-':
s += c
if item[0] == 'N':
s = '+' + s
if item[0] == 'S':
s = '-' + s
list2.append(s)
print(list2) # ['+30', '-15', '-60', '+70', '+10']
vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 39
Ok, if we are going to give (again) ready answer:
>>> values = [('+' if item.startswith('N') else ('-' if item.startswith('S') else '')) + item.rsplit(' ', 1)[-1] for item in list1]
>>> values
['+30', '-15', '-60', '+70', '+10']
>>>
pyTony
pyMod
6,331 posts since Apr 2010
Reputation Points: 879
Solved Threads: 990
Skill Endorsements: 27