data examples announcements examples objects land owners
play

Data Examples Announcements Examples: Objects Land Owners - PowerPoint PPT Presentation

Data Examples Announcements Examples: Objects Land Owners Instance attributes are found before class attributes; class attributes are inherited class Worker: <class Worker> >>> Worker().work() >>> Worker().work()


  1. Data Examples

  2. Announcements

  3. Examples: Objects

  4. Land Owners Instance attributes are found before class attributes; class attributes are inherited class Worker: <class Worker> >>> Worker().work() >>> Worker().work() greeting = 'Sir' 'Sir, I work' greeting: 'Sir' def __init__(self): self.elf = Worker >>> jack >>> jack def work(self): <class Bourgeoisie> Peon return self.greeting + ', I work' def __repr__(self): greeting: 'Peon' return Bourgeoisie.greeting >>> jack.work() >>> jack.work() 'Maam, I work' jack <Worker> class Bourgeoisie(Worker): greeting = 'Peon' >>> john.work() >>> john.work() elf: def work(self): Peon, I work greeting: 'Maam' print(Worker.work(self)) 'I gather wealth' return 'I gather wealth' john <Bourgeoisie> >>> john.elf.work(john) >>> john.elf.work(john) jack = Worker() 'Peon, I work' elf: john = Bourgeoisie() jack.greeting = 'Maam' 4

  5. Examples: Iterables & Iterators

  6. Using Built-In Functions & Comprehensions What are the indices of all elements in a list s that have the smallest absolute value? [-4, -3, -2, 3, 2, 4] [1, 2, 3, 4, 5] [2, 4] [0] 0 1 2 3 4 5 What's the largest sum of two adjacent elements in a list s? (Assume len(s) > 1) [-4, -3, -2, 3, 2, 4] [-4, 3, -2, -3, 2, -4] 6 1 Create a dictionary mapping each digit d to the lists of elements in s that end with d. [5, 8, 13, 21, 34, 55, 89] {1: [21], 3: [13], 4: [34], 5: [5, 55], 8: [8], 9: [89]} Does every element equal some other element in s? [-4, -3, -2, 3, 2, 4] [4, 3, 2, 3, 2, 4] False True 6

  7. Examples: Linked Lists

  8. Linked List Exercises Is a linked list s ordered from least to greatest? 1 3 4 1 4 3 Is a linked list s ordered from least to greatest by absolute value (or a key function)? 1 -3 4 1 4 -3 Create a sorted Link containing all the elements of both sorted Links s & t. 1 5 1 4 1 1 4 5 Do the same thing, but never call Link. x x 1 5 1 4 8

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend