python 的string数组如何按照字符串长短进行排序 [✀aa✀,✀zxczxc✀,✀a✀] => [✀a✀,✀a✀,✀zxczxc✀]

2024-11-20 20:18:21
推荐回答(3个)
回答1:

st= ['aa','zxczxc','a']
st.sort(key=lambda x: len(x))
print st

回答2:

list1=['aa','zxczxc','a']
list1.sort()
print list1

回答3:

print ['aa','zxczxc','a'].sort(key=lambda x: len(x))