Question: please provide python code for the following problems 1) https://www.codestepbystep.com/problem/view/python/collections/list/switch_pairs a = [a, bb, c, ddd, ee, f, g] switch_pairs(a) Your function should switch the

please provide python code for the following problems

1) https://www.codestepbystep.com/problem/view/python/collections/list/switch_pairs

a = ["a", "bb", "c", "ddd", "ee", "f", "g"] 
switch_pairs(a) 

Your function should switch the first pair ("a", "bb"), the second pair ("c", "ddd") and the third pair ("ee", "f"), to yield this list:

["bb", "a", "ddd", "c", "ee", "f", "g"] 

If there are an odd number of values, the element is not moved.

You may assume that the list is not None and that no element of the list is None.

2)https://www.codestepbystep.com/problem/view/python/collections/list/n_copies

Write a function named n_copies that accepts a list of integers a as a parameter and returns a new list a2, with each element value n from a replaced by nconsecutive copies of the value n at the same relative location in the list. For example, if a list named a stores the following element values:

[3, 5, 0, 2, 2, -7, 0, 4] 

Then the call of a2 = n_copies(a) should return a new list a2 containing the following elements. The idea is that the value 3 was replaced by three 3s the 5 was replaced by five 5s and so on.

[3, 3, 3, 5, 5, 5, 5, 5, 2, 2, 2, 2, 4, 4, 4, 4] 

Any element whose value is 0 or negative should not be kept in the returned list (as with 0 and -7 above).

Constraints: In solving this problem, you must create a single new list to be returned, but aside from that, do not create any other data structures such as temporary lists or strings. You may use as many simple variables (such as ints) as you like.

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!