LastRecitationProxy

.pdf

School

Rutgers University *

*We aren’t endorsed by this school

Course

198:336

Subject

Computer Science

Date

Jan 9, 2024

Type

pdf

Pages

15

Uploaded by MinisterWallaby3964

Report
Strings and Loops: Write a Python function duplicate_chars that takes a string as input and returns a new string where each character in the original string is repeated twice. For example, duplicate_chars('abc') should return 'aabbcc'.
List Comprehension: Given a list of numbers, write a single line of Python code using list comprehension to create a new list which contains only the odd numbers from the original list multiplied by 2.
Tuples and Functions: Write a Python function max_min_avg that takes a list of tuples, where each tuple contains three numbers. The function should return a tuple containing the maximum, minimum, and average of all the numbers in the input list of tuples. For example, max_min_avg([(1, 2, 3), (4, 5, 6)]) should return (6, 1, 3.5).
Dictionaries and Loops: Write a Python function invert_dict that takes a dictionary as input and returns a new dictionary where the keys are the values of the original dictionary and the values are lists of keys from the original dictionary that had the corresponding value. Assume all values are hashable.
Inline Function Lambda and List Comprehension: Write a single line of Python code that uses lambda function and list comprehension to create a list of squares of all even numbers from 0 to 20 (inclusive).
Loops and String Manipulation: Write a Python function string_alternate that takes a string as input and returns a new string consisting of every alternate character from the original string, starting with the first character. For example, string_alternate('abcdef') should return 'ace'.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help