Git Product home page Git Product logo

epai3-session12's Introduction

Iterators and iterable II

Assignment Question

Project: Description

  • The starting point for this project is the Polygon class and the Polygons sequence type we created in the previous project.

The code for these classes along with the unit tests for the Polygon class are below if you want to use those as your starting point. But use whatever you came up with in the last project.

  • We have two goals:

Goal 1

  • Refactor the Polygon class so that all the calculated properties are lazy properties, i.e. they should still be calculated properties, but they should not have to get recalculated more than once (since we made our Polygon class "immutable").

Goal 2

  • Refactor the Polygons (sequence) type, into an iterable. Make sure also that the elements in the iterator are computed lazily - i.e. you can no longer use a list as an underlying storage mechanism for your polygons.

You'll need to implement both an iterable, and an iterator.

Test Cases

Test cases have been developed in the notebook to check the Goal 1 and Goal 2. There are two sections in the notebook, first section tests objective 1 over properties, __repr__,__eq__ & __gt__ function. The second section contains the test cases for objective 2 over properties,__repr__, __len__ & __getitem__.

repr

In Python, repr is a special method used to represent a class's objects as a string.

eq

Python automatically calls the eq method of a class when you use the == operator to compare the instances of the class

gt

gt (a, b) Perform “rich comparisons” between a and b. Specifically, lt(a, b) is equivalent to a < b , le(a, b) is equivalent to a <= b , eq(a, b) is equivalent to a == b , ne(a, b) is equivalent to a != b , gt(a, b) is equivalent to a > b and ge(a, b) is equivalent to a >= b

len

Well, len(s) is a built-in Python method which returns the length of an object. Now len() is a special method that is internally called by len(s) method to return the length of an object. So, when we call len(s) method, s. len() is what actually happening behind the scenes to calculate the length.

getitem

The method getitem(self, key) defines behavior for when an item is accessed, using the notation self[key]

iter

The iter() function returns an iterator object that goes through the each element of the given object.

next

The next element can be accessed through next() function.

epai3-session12's People

Contributors

umeshtriveni avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.