4. Write a function remove_repetition that takes any list 1st and returns a new list with the same entries as 1st, except all instances of consecutive repetition are no longer present. For example, remove_repetition([3, 4, 4, 6, 4, 3, 3, 3, 1]) should return the new

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.1: Function And Parameter Declarations
Problem 2E
icon
Related questions
Question
Python help
You will create and submit a single script including each of the following function definitions (see
the assignment page in Canvas for a starter script). Remember to pay close attention to whether
your result should be return ed or print ed.
You should print enough test cases below each of your function definitions to be reasonably
sure it works for all types of inputs as described in the problem. Your test cases should be
different from any of the examples provided in the problem.
FOr all questions on Part 2, you may not use any buill-in functions or methods other than
range,
len,
and append.
1. A list of mumbers is said to be balanced if the sum of its first half is cqual to the sumn of its
second half (if the list has odd length, then we ignore the center value in both sums). Write
a function is balanced that takes any list of numbers num list and returns True if the
Transcribed Image Text:You will create and submit a single script including each of the following function definitions (see the assignment page in Canvas for a starter script). Remember to pay close attention to whether your result should be return ed or print ed. You should print enough test cases below each of your function definitions to be reasonably sure it works for all types of inputs as described in the problem. Your test cases should be different from any of the examples provided in the problem. FOr all questions on Part 2, you may not use any buill-in functions or methods other than range, len, and append. 1. A list of mumbers is said to be balanced if the sum of its first half is cqual to the sumn of its second half (if the list has odd length, then we ignore the center value in both sums). Write a function is balanced that takes any list of numbers num list and returns True if the
4. Write a function remove_repetition that takes any list 1st and returns a new list with
the same entries as 1st , except all instances of consecutive repetition are no longer present.
For example, remove_repetition([3, 4, 4, 6, 4, 3, 3, 3, 1]) should return the new
2
list [3, 4, 6, 4, 3, 1] .
5. Write a function n_gram that takes any string word and a positive integer n, and that
returns a list containing all adjacent substrings of length n in word
For example, n_gram('hello', 2) should return the list ['he', 'el', 'll', 'lo'].
and n gram ('science', 5) should return the list ['scien', 'cienc', 'ience']. If n
is larger than len (word), then the list returned should be empty.
Transcribed Image Text:4. Write a function remove_repetition that takes any list 1st and returns a new list with the same entries as 1st , except all instances of consecutive repetition are no longer present. For example, remove_repetition([3, 4, 4, 6, 4, 3, 3, 3, 1]) should return the new 2 list [3, 4, 6, 4, 3, 1] . 5. Write a function n_gram that takes any string word and a positive integer n, and that returns a list containing all adjacent substrings of length n in word For example, n_gram('hello', 2) should return the list ['he', 'el', 'll', 'lo']. and n gram ('science', 5) should return the list ['scien', 'cienc', 'ience']. If n is larger than len (word), then the list returned should be empty.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Introduction to computer system
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning