Sort results non-lexicographically?

后端 未结 5 1730
轮回少年
轮回少年 2021-02-19 21:29

I\'m trying to display some results in a human-readable way. For the purposes of this question, some of them are numbers, some are letters, some are a combination of the two.

5条回答
  •  感动是毒
    2021-02-19 22:23

    For your specific case:

    def mySort(l):
        numbers = []
        words = []
        for e in l:
            try:
                numbers.append(int(e))
            except:
                words.append(e)
        return [str(i) for i in sorted(numbers)] + sorted(words)
    
    print mySort(input)
    

提交回复
热议问题