9.17. Exercises¶
For each word in the list
verbs
, add an -ing ending. Overwrite the old list so thatverbs
has the same words withing
at the end of each one.In XYZ University, upper level math classes are numbered 300 and up. Upper level English classes are numbered 200 and up. Upper level Psychology classes are 400 and up. Create two lists,
upper
andlower
. Assign each course inclasses
to the correct list,upper
orlower
. HINT: remember, you can convert some strings to different types!Starting with the list myList = [76, 92.3, ‘hello’, True, 4, 76], write Python statements to do the following:
Append “apple” and 76 to the list.
Insert the value “cat” at position 3.
Insert the value 99 at the start of the list.
Find the index of “hello”.
Count the number of 76s in the list.
Remove the first occurrence of 76 from the list.
Remove True from the list using
pop
andindex
.
The module
keyword
determines if a string is a keyword. e.g.keyword.iskeyword(s)
wheres
is a string will return eitherTrue
orFalse
, depending on whether or not the string is a Python keyword. Import thekeyword
module and test to see whether each of the words in listtest
are keywords. Save the respective answers in a list,keyword_test
.The
string
module provides sequences of various types of Python characters. It has an attribute calleddigits
that produces the string ‘0123456789’. Import the module and assign this string to the variablenums
. Below, we have provided a list of characters calledchars
. Usingnums
andchars
, produce a list calledis_num
that consists of tuples. The first element of each tuple should be the character fromchars
, and the second element should be a Boolean that reflects whether or not it is a Python digit.