Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sort list of strings numerically

# Example usage:
your_list = ['cmd1','cmd10', 'cmd111', 'cmd50', 'cmd99']
your_list.sort(key=lambda x: int(x[3:]))
print(your_list)
--> ['cmd1', 'cmd10', 'cmd50', 'cmd99', 'cmd111']
Source by cmdlinetips.com #
 
PREVIOUS NEXT
Tagged: #python #sort #list #strings #numerically
ADD COMMENT
Topic
Name
2+1 =