📜  python代码示例中元组的高级使用

📅  最后修改于: 2022-03-11 14:45:23.194000             🧑  作者: Mango

代码示例1
## Say we have a list of strings we want to sort by the last letter of the string.  strs = ['xc', 'zb', 'yd' ,'wa'] 
  ## Write a little function that takes a string, and returns its last letter. 
  ##This will be the key function (takes in 1 value, returns 1 value).  def MyFn(s):    return s[-1]  
  ##Now pass key=MyFn to sorted() to sort by the last letter:  print sorted(strs, key=MyFn) 
  ## ['wa', 'zb', 'xc', 'yd']