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

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...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified:...
#Python 5. Write function called evaluate() that evaluates the following Python expressions or assignments as specified: Request input from the user for three variables (floating-point or integer) x, y, z, and myAverage. If the average of the first three numbers equals the fourth number, print 'Your average is correct.'. If not print 'Your average is not correct'. and print the correct average. Print the largest value among x, y, and z. Print the minimum value of x, y, y. >>>...
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT