Q3. Consider the following Python function: If we call the function maf with the list a and then with the list b with the values give bellow: a = [17, 38, 10, 25, 72] b = [10, 30, 20, 30, 10] What is the value returned by each call? Answers (choose one): a) maf(a) returns True and maf(b) returns True
Tag: reverse
Reversing two elements in list, based on condition
I’m trying to implement a Bubble Sort algorithm. As it says here, the “Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order.” Visual Representation ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ) So far, I have been able to identify
How do I reverse a list using while loop?
Input list: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] I know how to do it with for loop, but my assignment is to do it with while loop; which I have no idea to do. Here is the code I have so far: Answer I would say to make the while loop act like a for
How to reverse an int in python?
I’m creating a python script which prints out the whole song of ’99 bottles of beer’, but reversed. The only thing I cannot reverse is the numbers, being integers, not strings. This is my full script, I understand my reverse function takes a string as an argument, however I do not know how to take in an integer, or ,
Print a list in reverse order with range()?
How can you produce the following list with range() in Python? Answer use reversed() function: It’s much more meaningful. Update: If you want it to be a list (as btk pointed out): Update: If you want to use only range to achieve the same result, you can use all its parameters. range(start, stop, step) For example, to generate a list