Sort a list of object identifiers: Difference between revisions

Line 297:
 
.say for sort &naturally, <...>;</lang>
 
=={{header|Python}}==
 
We need to split the input and map each part to int otherwise elements gets compared as a string
<lang Python>
data = [
'1.3.6.1.4.1.11.2.17.19.3.4.0.10',
'1.3.6.1.4.1.11.2.17.5.2.0.79',
'1.3.6.1.4.1.11.2.17.19.3.4.0.4',
'1.3.6.1.4.1.11150.3.4.0.1',
'1.3.6.1.4.1.11.2.17.19.3.4.0.1',
'1.3.6.1.4.1.11150.3.4.0'
]
 
for s in sorted(data, key=lambda x: list(map(lambda x: int(x), x.split('.')))):
print(s)
</lang>
 
=={{header|Racket}}==
Anonymous user