Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a list of 100 random strings of random length between 5 and 8 characters and consisting of upper and lower case characters. Use the

image text in transcribed
Create a list of 100 random strings of random length between 5 and 8 characters and consisting of upper and lower case characters. Use the random functions that we discussed in class to create the strings. You can use the following to create a list of all upper and lower case letters. 2. Letters [ sorted(chr(cx) for c in range(97,123) for x in (0,32)1 As you can see above, a lambda is a simple function that has no name and can be used anywhere that a function can be used. The syntax of the Python lambda is: lambda variable_list: definition ex. lambda x x**5 or another using two variables lambda (x,y):x-5 +3 when used in the sorted function the variable will apply to each item in the list to be sorted. You don't have to manually do anything else. For example: ?[ Zebra',' Mallet','Ant','Angel','Demon'] M [4, 5, 2, 8] L- sorted(L, key lambda x: len(x)) sorts the list based on the length of each item L sorted(L, key lambda x: x[2]) sorts the list based on the third character in each item. It will give an error if one of the items is too short. We could change it to use a slice and it will work fine. L- sorted(L, key lambda x: x[3:4]) Lambdas can be assigned to a variable and then used list a function call. For example, H - lambda xy:x3+y+8 assigns the lambda to H, now H(2,5) will invoke the lambda and return the calculated value of 2**3+5+8 or 21. sorted() also has an option to reverse the sort. So L- sorted(L, key- len, reverse- True) sorts the list from longest to shortest. Notice we didn't use a lambda in this sort but just the function name that we applied

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago