Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python please; 1a.) Write a function called double_list(nums) that takes in a list of integers as an argument and returns a new list where each

python please;

1a.) Write a function called double_list(nums) that takes in a list of integers as an argument and returns a new list where each integer is multiplied by 2. You should use a for loop and the append() method to construct the new list.

Test case:

nums = [1, 2, 3, 4, 5] result = double_list(nums) print(result) # Output: [2, 4, 6, 8, 10]

1b.) Write a function called sum_concat(my_dictionary) that takes in a dictionary my_dictionary as an argument and returns a tuple containing the sum of all the values in the dictionary and the concatenation of all the keys in the dictionary as a string. Use the .items() method to iterate through the key-value pairs of the dictionary.

Test case:

my_dict = {'a':1, 'b':2, 'c':3} result = sum_concat(my_dict) print(result) # Output: (6, 'abc')

1c.)

Write a function called reverse_queue(queue) that takes in a queue as an argument and modifies the queue so that its elements are in reverse order. You should use a stack data structure to reverse the order of the elements.

Test case:

from collections import deque queue = deque(["a", "b", "c", "d"]) reverse_queue(queue) print(queue) # Output: deque(["d", "c", "b", "a"])

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

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions