How can I return the trailing set of numbers from a list of strings?
mylist = ['kys_q1a2','kys_q3a20','kys_q2889b244','sonyps3_q92c288888']
expected result:
[2, 20, 244, 288888]
My failed attempt:
for item in mylist:
print item[-1]
Context:
Each item in the list represents question name and consist of 2 parts:
I've tried to show the various ways they can be shown.
You can use regex:
>>> import re
>>> r = re.compile(r'\d+$')
>>> [int(m.group()) for m in (r.search(item) for item in mylist) if m]
[2, 20, 244, 288888]