Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions