Answers for "advanced use of tuples in python"

0

advanced use of tuples in python

  ## 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']
Posted by: Guest on July-29-2021

Code answers related to "advanced use of tuples in python"

Python Answers by Framework

Browse Popular Code Answers by Language