Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This problem has you write a nested loop to process a list of list of int, and accumulate a list of list of int. The starter code #provides an accumulator for the result and a loop over the lists, and you need to write the code that checks whether sublist #contains only even ints.
- #
- #You'll probably want a one-way flag: a Boolean variable that starts out as True and is set to False if you find an odd int in the #sublist. You'll need to check the value of this variable to figure out whether to append sublist to the even_lists accumulator.
- def only_evens(lst):
- """ (list of list of int) -> list of list of int
- Return a list of the lists in lst that contain only even integers.
- >>> only_evens([[1, 2, 4], [4, 0, 6], [22, 4, 3], [2]])
- [[4, 0, 6], [2]]
- """
- even_lists = []
- check = 0
- for sublist in lst:
- for item in sublist:
- if item % 1 == check:
- even_lists.append(sublist)
- return even_lists
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement