Anonymous user
Sort a list of object identifiers: Difference between revisions
Sort a list of object identifiers (view source)
Revision as of 18:27, 17 February 2017
, 7 years ago→{{header|Python}}
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}}==
|