{"id":20041697,"url":"https://github.com/ajithvcoder/session_11_iterablesanditerators_1","last_synced_at":"2026-05-13T06:02:28.938Z","repository":{"id":111987628,"uuid":"388859750","full_name":"ajithvcoder/Session_11_IterablesandIterators_1","owner":"ajithvcoder","description":null,"archived":false,"fork":false,"pushed_at":"2021-07-23T16:28:51.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-12T19:28:49.446Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajithvcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-07-23T16:19:38.000Z","updated_at":"2021-07-23T16:28:54.000Z","dependencies_parsed_at":"2023-09-09T21:30:49.332Z","dependency_job_id":null,"html_url":"https://github.com/ajithvcoder/Session_11_IterablesandIterators_1","commit_stats":null,"previous_names":["ajithvcoder/session_11_iterablesanditerators_1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_11_IterablesandIterators_1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_11_IterablesandIterators_1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_11_IterablesandIterators_1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_11_IterablesandIterators_1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajithvcoder","download_url":"https://codeload.github.com/ajithvcoder/Session_11_IterablesandIterators_1/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470401,"owners_count":19968041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T10:47:33.868Z","updated_at":"2026-05-13T06:02:23.900Z","avatar_url":"https://github.com/ajithvcoder.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Session 11 - Iterables and Iterators - I\n\nGoogle Colab - [here](https://colab.research.google.com/drive/1hEFlhwuSk2q4kCKAXqZdj83YMD3H3aEX?usp=sharing)\n\n#### Iterator\n\niterator is a object that helps to iterate over iterable objects like list, tuples. it uses __iter__ for initalization and uses next() method for iteration\n\n```\n        def __iter__(self):\n            print(\"Calling PolygonIterator instance __iter__\")\n            return self \n```\n\nit is used when below function is done \n```\npolygons = Polygons(6, 10)\niter_poly = iter(polygons)\n```\n\n#### next()\n\n```\n        def __next__(self):\n            print(\"Calling PolygonIterator __next__\")\n            if self._index \u003e= len(self._poly_obj):\n                raise StopIteration\n            else:\n                item = self._poly_obj._polygons[self._index]\n                self._index += 1\n                return item\n\n```\nnext() is used to fetch the next item(iterable) in a iterator. When it has fetched all the objects it raises a exception StopIteration. once all the items are exhausted , exception is raised and it denotes end of iterator.\n\n#### getitem()\n\n```\n        def __getitem__(self, num) -\u003e 'list':  \n            \"\"\" \n            :param num: edges of a polygon\n            :type num: int        \n            :return class: \n            \"\"\"       \n            return self._polygons[num]\n```\n\ngetitem() is used to fetch a particular item in a list and also it helps while forming a new list\n\n#### Iterable\n\nEven when we iterate over a object again and again with for loop it should not get exhausted i.e there should be no need for re-initalization\n\n```\n    polygons = Polygons(4, 10)\n    polygons_list = []\n    for poly in polygons:\n        polygons_list.append(poly)\n        print(poly)\n    for poly in polygons:\n        polygons_list.append(poly)\n        print(poly)\n```\n\n#### list()\n\nEven when we call the object with list(obj) it should apt number of outputs\n\n```\npolygons = Polygons(10, 10)\nassert len(list(polygons)) == 8\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Fsession_11_iterablesanditerators_1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajithvcoder%2Fsession_11_iterablesanditerators_1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Fsession_11_iterablesanditerators_1/lists"}