## Description

import doctest

def get_digits(s):

”'(str) -> str

Parameter s is a string of non-negative ints and words separated by spaces.

Return a new string containing all the ints in s separated by spaces. Hint: You may

need to take care of removing repeated spaces in your final string.

>>> get_digits(‘1 word 2 words 3 more’)

‘1 2 3′

>>> get_digits(’10 characters 20 30 more’)

’10 20 30′

”’

pass # replace with your code

def max_numbers(s):

”'(str) -> int

Assume s is a string of non-negative integers seperated by spaces. Return the max of

the integers in s.

Requirement: Do NOT use lists (or any of your other

functions). You must use a for loop. You may assume s is non-empty.

>>> max_numbers(’45’)

45

>>> max_numbers(’34 3 542 11′)

542

”’

pass # replace with your code

def max_ints_mixed(s):

”'(str) -> int

Assume s is a string of non-negative integers and words separated by spaces. Return

the max of the integers in s.

Requirements: You may NOT use lists. Your solutions should be ONE LINE of code. You

should call some of the functions in this exercise. You may assume there is at least

one int in the string and ints are separated by spaces, for example, ‘a20’ is not

considered to be an int.

>>> max_ints_mixed(‘3’)

3

>>> max_ints_mixed(‘my sister is 10 years and 11 months old.’)

11

”’

pass # replace with your code

# Now lets do it again with lists! Lists make it easier!!

def get_digits_list(mixed_list):

”'(list of str) -> list of int

Parameter mixed_list is a list of strs representing words and

non-negative ints. Return a new list of integers containing

the strs representing ints from mixed_list, converted to ints.

>>> get_digits_list([’45’, ‘banana’, ‘3’, ‘2001’, ‘3 apples’])

[45, 3, 2001]

>>> get_digits_list([‘banana’, ‘apple’])

[]

>>> get_digits_list([‘3′, ’15’, ’16’])

[3, 15, 16]

>>> get_digits_list([])

[]

”’

pass # replace with your code

def max_ints_mixed2(s):

”'(str) -> int

Assume s is a str of words and non-negative ints separated by spaces. Return the

max of the ints in s.

Requirement: Your function must be only 1 line long. You should use lists and your

get_digits_list function. You may assume there is at least one int in the string and

ints are separated by spaces, for example, ‘a20′ does not have any ints in it.

>>> max_ints_mixed2(“45 silly 80”)

80

>>> max_ints_mixed2(“There are 350 students in csca20 and 900 in csca67″)

900

”’

pass # replace with your code

if __name__ == ‘__main__’:

doctest.testmod(verbose = True)