Question

In: Computer Science

Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal",...

Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal", "python", "break", "two", "ruby"] by: a) the last 2 characters of each list item in reverse order b) create new list from list above where each item has only 3 characters and first one is capitalized. For example, the list item = "democratic" will transform into "Dem". Apply alphabetically sorting to the new list.  

Solutions

Expert Solution

Program Code Screenshot

Sample Output

Program Code to Copy

l = ["democratic", "republican", "equal", "python", "break", "two", "ruby"]
#Sort the list by last 2 chars
l.sort(key=lambda x : x[-2:],reverse=True)
print('After sorting by last 2 chars ')
print(l)
#Create a new list by taking first 3 chars
nl = [x[0].upper()+x[1:3] for x in l]
print('New list by taking first 3 chars ',nl)

nl.sort()
print('After sorting alphabetically : ')
print(nl)


Related Solutions

Write a Python program containing a function named scrabble_sort that will sort a list of strings...
Write a Python program containing a function named scrabble_sort that will sort a list of strings according to the length of the string, so that shortest strings appear at the front of the list. Words that have the same number of letters should be arranged in alphabetical order. Write your own logic for the sort function (you may want to start from some of the existing sorting code we studied). Do NOT use the built-in sort function provided by Python....
how do you write a bubble sort function in python that sorts a linked list and...
how do you write a bubble sort function in python that sorts a linked list and if any duplicate are placed bext ti each other?
write and essay on how Montesquieu makes a distinction between two types of republican governments: democratic...
write and essay on how Montesquieu makes a distinction between two types of republican governments: democratic and aristocratic. What distinguishes these two types of government (please discuss with respect to both their institutional form (nature) and their animating spirit (principle))? What are each republican form of government’s strengths and weaknesses?
1.)recursive merge sort on a list.(Python) 2.)recursive bubble sort using a list without enumerate() function.(python) Show...
1.)recursive merge sort on a list.(Python) 2.)recursive bubble sort using a list without enumerate() function.(python) Show Base case, and recursive case.
Write in python: Go through the visualization of the Selection Sort, Bubble Sort and Insertion Sort....
Write in python: Go through the visualization of the Selection Sort, Bubble Sort and Insertion Sort. Write a Pseudo code first for each of these sort methods. After writing the pseudo code write python code from the pseudo code.
In Python, there are different sorting algorithms. Selection Sort, Bubble Sort and Insertion Sort. • Write...
In Python, there are different sorting algorithms. Selection Sort, Bubble Sort and Insertion Sort. • Write a Pseudo code first for each of these sort methods.   • After writing the pseudo code write python code from the pseudo code. • Upload the pseudo code and Python code for each of the three algorithm mentioned.
Write a program in Python to practice evaluating some logical expressions and determine whether the expressions...
Write a program in Python to practice evaluating some logical expressions and determine whether the expressions are equivalent. Read in a 0 or 1 integer value for each of the following variables: A, B, C, and D. Use an if…else statement to change the 0 and 1 integer values into True and False Boolean values. Booleans in Python have to have this capitalization (True/False, not true/false or TRUE/FALSE) and shouldn’t contain double quotes (which makes them a String instead of...
Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the...
Question4: Create and use a lambda expression which calculates the sum of three numbers. Ask the user for three numbers and use the lambda function to print the sum [6 marks] Question5: Write a generator function which generates the Fibonacci series. [0,1,2,4,8,16,…]. The Fibonacci series is a list of numbers where each number is the sum of the previous two. [3 marks] Then write the code to iterate through the first six numbers of sequence. [3 marks] Question6: Write a...
Regular expressions are used in Python for describing and identifying specific patterns. In Python, we use...
Regular expressions are used in Python for describing and identifying specific patterns. In Python, we use “re” or “Regex” to denote regular expressions. Write the Python Code to return matching analytics word in the following given text. Write the Python Code to return how many times analytics word is provided in this text. Definitions are useful to the extent they serve a purpose. So, is defining analytics important? Yes and no. It’s not likely that we’ll ever arrive at a...
ASAP Use python please!! Write a program including   binary-search and merge-sort in Python. You also need to  modify...
ASAP Use python please!! Write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT