[go: up one dir, main page]

0% found this document useful (0 votes)
27 views1 page

ws18 Lists Parallel Worksheet

The document contains a worksheet for CSC108H Winter 2024, focusing on two functions: 'stretch_string' and 'greatest_difference'. Each function includes a description, preconditions, and example usage that need to be completed. The worksheet aims to enhance understanding of parallel strings and lists in programming.

Uploaded by

Roger Antoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

ws18 Lists Parallel Worksheet

The document contains a worksheet for CSC108H Winter 2024, focusing on two functions: 'stretch_string' and 'greatest_difference'. Each function includes a description, preconditions, and example usage that need to be completed. The worksheet aims to enhance understanding of parallel strings and lists in programming.

Uploaded by

Roger Antoun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CSC108H Winter 2024 Worksheet 18 : Parallel Strings and Lists

For each function, complete the examples in the docstring and then complete the function body.

1. def stretch_string(s: str, stretch_factors: list[int]) -> str:


"""Return a string consisting of the characters in s in the same order as in s,
repeated the number of times indicated by the item at the corresponding
position of stretch_factors.

Precondition: len(s) == len(stretch_factors) and the values in


stretch_factors are non-negative

>>> stretch_string('Hello', [2, 0, 3, 1, 1])


'HHllllo'
>>> stretch_string('echo', [0, 0, 1, 5])

"""

2. def greatest_difference(nums1: list[int], nums2: list[int]) -> int:


"""Return the greatest absolute difference between numbers at corresponding
positions in nums1 and nums2.

Precondition: len(nums1) == len(nums2) and nums1 != []

>>> greatest_difference([1, 2, 3], [6, 8, 10])


7
>>> greatest_difference([1, -2, 3], [-6, 8, 10])

"""

You might also like