Basic Exercises¶
Basic Exercises from Google’s Python Class
Given a list of strings, return a list with the strings in sorted order, except group all the strings that begin with ‘x’ first. For example: [‘mix’, ‘xyz’, ‘apple’, ‘xanadu’, ‘aardvark’] yields [‘xanadu’, ‘xyz’, ‘aardvark’, ‘apple’, ‘mix’]
Given a list of strings, return the count of the number of strings where the string length is 2 or more and the first and last chars of the string are the same.
Given a list of non-empty tuples, return a list sorted in increasing order by the last element in each tuple.
Given an int count of a number of donuts, return a string of the form ‘Number of donuts: <count>’, where <count> is the number passed in. However, if the count is 10 or more, then use the word ‘many’ instead of the actual count.
Given a string s, return a string made of the first 2 and the last 2 chars of the original string, so ‘spring’ yields ‘spng’. However, if the string length is less than 2, return instead the empty string.
Given a string s, return a string where all occurrences of its first char have been changed to ‘*’, except do not change the first char itself. For example, ‘babble’ yields ‘ba**le’. Assume that the string is length 1 or more.
Given strings a and b, return a single string with a and b separated by a space ‘<a> <b>’, except swap the first 2 chars of each string.