3 ms·
That is a neat trick, but it would be incredibly brittle. Kids, don't try this at home!
by daveguy 11y ago
That is a neat trick, but it would be incredibly brittle. Kids, don't try this at home!
- solaxun 11y agoPass in an re.match or re.search based function, i would imagine that would be powerful enough to meet most needs. import re x = ['foo12901','fooo900','fooooooo980090'] x =sorted(x,key = lambdax:int(re.search('\d+',x).group())) print(x)
- shoyer 11y ago+1 this is the right way to build a custom sorting function. The only thing worse than relying on ad-hoc heuristics for processing your data is relying on heuristics that somebody else maintains!