CSC148H1 Study Guide - Midterm Guide: Docstring, Linked List, Binary Search Tree

149 views3 pages
25 Oct 2018
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

Read the docstring below for method remove rst double. Linkedlistnode methods provided are those in the api. def remove_first_double(self): Remove second of two adjacent nodes with duplicate values. If there is no such node, leave self as is. No need to deal with subsequent adjacent duplicate values. 3 -> 2 -> 3 -> 3 ->| if self. size < 2: # no room for doubles return none else: current_node = self. front while (current_node. next_ and current_node. value != current_node. next_. value): current_node = current_node. next_ if current_node. next_ is not none: current_node. next_ = current_node. next_. next_ if current_node. next_ is none: self. back = current_node self. size -= 1. Read the docstring for function contains satis er below, and then implement it. Return whether possibly-nested list_ contains a non-list element that satisfies (returns true for) predicate. @param list list_: list to check for predicate satisfiers. >>> list_ = [5, [6, [7, 8]], 3] False return any([contains_satisfier(c, predicate) if isinstance(c, list) else predicate(c) for c in list_])