Python — Funtcions with lists

In this problem you must implement several functions on lists in Python.

  1. Write a function @myLength(L)@ that, given a list, returns its length.

  2. Write a function @myMaximum(L)@ that, given a non-empty list, returns its maximum.

  3. Write a function @average(L)@ that, given a non-empty list of numbers, returns its average.

  4. Write a function @buildPalindrome(L)@ that, given a list, returns the palindrome that starts with the reverse of the list.

  5. Write a function @remove(L1, L2)@ that, given a list L1L1 and a list L2L2, returns the list L1L1 after removing the occurrences of the elements in L2L2.

  6. Write a function @flatten(L)@ that recursively flattens a list whose elements may also be lists of different levels. Hint: use recursion and the @isinstance(x, list)@ built-in function.

  7. Write a function @oddsNevens(L)@ that, given a list of integers, returns two lists, one with all the odd numbers and one with all the even numbers, in the same relative order than the original.

  8. Write a function @primeDivisors(n)@ that returns the list of all prime divisors of a non-zero positive integer.

Scoring

Each function scores 12 points and the sample 4.

Sample session

Problem information

Author: Unknown
Translator: Jordi Petit

Generation: 2026-01-25T11:08:12.367Z

© Jutge.org, 2006–2026.
https://jutge.org