Question: First Function Write a function named 'swap' that is passed in a list and 2 index numbers (your function can assume these index numbers are

First Function Write a function named 'swap' that is passed in a list and 2 index numbers (your function can assume these index numbers are between 0 and len() - 1, inclusive). Your function should swap the values at those index locations. Notice that the 'swap' function does not print anything itself, and it does not return a value. It's only job is to modify (change) the list passed in as a parameter. For example:

stuff = [10, 20, 30, 40] print(stuff) swap(stuff, 0, 2) print(stuff) nums = [5, 8, 15, 12, 18] print(nums) swap(nums, 2, 3) print(nums)

Would display:

[10, 20, 30, 40] [30, 20, 10, 40] [5, 8, 15, 12, 18] [5, 8, 12, 15, 18]

After you write your function definition, write some test code to check that your function works properly. Second Function Write a function that is passed in a list of strings and returns a new list with all the strings of the original list with length 2 (the original list should not be changed). TIP: the built-in len() function can be used to determine the number of characters in a string. For example:

stuff = ['this', 'is', 'a', 'list', 'of', 'strings', 'yo'] print(stuff) others = sift_two(stuff) print(others) print(stuff)

Would display:

['this', 'is', 'a', 'list', 'of', 'strings', 'yo'] ['is', 'of', 'yo'] ['this', 'is', 'a', 'list', 'of', 'strings', 'yo']

After you write your function definition, write some test code to check that your function works properly. When testing, include cases that confirm that the function can find a 2-character string at the beginning and end of the original list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!