-1

My list looks this:

l = ['abcdbcex', 'abcdbc1fz', 'abcdcd11', 'abcd11a5']

I want to sort it in a way that it will become:

l = ['abcd11a5', 'abczbc1fz', 'abcfbcex', 'abcecd11']

So sort in ascending order, but skipping first 4 letters, also skipping everything after the 7th letter.

I have tried doing: sorted(list, key=lambda x:x[:4])

but this does not skip the first 4 letters, because I don't know how to do it.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

1 Answers1

2

You can't call it list, it's a reserved word. THis does work though:

sorted(xlist,key=lambda s: s[4:])

['abcd11a5', 'abcdbc1fz', 'abcdbcex', 'abcdcd11']
Sergio Lucero
  • 862
  • 1
  • 12
  • 21