Sort elements with specific order in python

前端 未结 3 453
我寻月下人不归
我寻月下人不归 2020-12-06 02:03

How can I sort it by custom order?

Input:

[
    {value: \"typeA\"},
    {value: \"typeC\"},
    {value: \"typeB\"},
    {value: \"typeC\"},
    {valu         


        
3条回答
  •  自闭症患者
    2020-12-06 02:47

    Taking an input and set the order in my_order and it will print in that order

    enter code here
    
    user_input = input()
    my_order = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1357902468'
    print(*sorted(user_input, key=my_order.index),sep='')
    

提交回复
热议问题