--Originally published at マルコ
6- Define a function sum()
and a function multiply()
that sums and multiplies (respectively) all the numbers in a list of numbers. For example, sum([1, 2, 3, 4])
should return 10
, and multiply([1, 2, 3, 4])
should return 24
.
7- Define a function reverse()
that computes the reversal of a string. For example, reverse("I am testing")
should return the string "gnitset ma I"
.
8- Define a function is_palindrome()
that recognizes palindromes (i.e. words that look the same written backwards). For example, is_palindrome("radar")
should return True
.
9- Write a function is_member()
that takes a value (i.e. a number, string, etc) x
and a list of values a
, and returns True
if x
is a member of a
, False
otherwise. (Note that this is exactly what the in
operator does, but for the sake of the exercise you should pretend Python did not have this operator.)
10- Define a function overlapping()
that takes two lists and returns True if they have at least one member in common, False otherwise. You may use your is_member()
function, or the in
operator, but for the sake of the exercise, you should (also) write it using two nested for-loops.
Featured image:
http://abduction.ml/post/157801322005