I have strings that look like "co1/co2", "co3/co4" ... "co11/co12"
describing it as a regex:
^(?P<prefix>\w\w)(?P<month>\d+)/(?P<prefix2>\w\w)(?P<month2>\d+)$
I want to sort a collection of these strings based on the equivalent of the "month" group of the regex. (the first number in the string (eg. the "1" in 'co1/co2' or the "12" in 'co12/co13')
I'm unable to figure out a lambda function I can use in sorted() that will do this for me, though.
wrong_order = [u'co1/co2', u'co10/co11', u'co11/co12', u'co12/co13', u'co2/co3',
u'co3/co4', u'co4/co5', u'co5/co6', u'co6/co7', u'co7/co8', u'co8/co9',
u'co9/co10']
correct_order = [u'co1/co2', u'co2/co3', u'co3/co4', u'co4/co5', u'co5/co6', \
u'co6/co7', u'co7/co8', u'co8/co9', u'co9/co10', u'co10/co11', u'co11/co12', u'co12/co13']
#this lambda function doesn't work
output = sorted(wrong_order, key=lambda x: (x[2:]))
co02instead ofco2x[2:]is a string. You need to convert that string to a number