Exercises: Lists, Loops, Functions¶
Exercises¶
Modify the prime number detection program from one of the previous exercises: make the prime number detection a function, and call the function instead. The function (
is_prime()
is a likely name) takes a number, and returns a boolean value as appropriate.Write a function
uniq()
that takes a sequence as input. It returns a list with duplicate elements removed, and where the contained elements appear in the same order that is present in the input sequence. The input sequence remains unmodified.Write a function
join()
that takes a string liststrings
and a stringseparator
as parameter. It joinsstrings
together into a single string, usingseparator
as a separator. For example,join(['Hello', 'World'], '-')
returns'Hello-World'
join(['Hello'], '-')
returns'Hello'