{"id":20041707,"url":"https://github.com/ajithvcoder/session_9_tuples-namedtuples","last_synced_at":"2025-09-23T16:29:05.653Z","repository":{"id":111987608,"uuid":"384520794","full_name":"ajithvcoder/Session_9_Tuples-NamedTuples","owner":"ajithvcoder","description":"Assignment","archived":false,"fork":false,"pushed_at":"2021-07-10T04:52:28.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T09:07:25.036Z","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-09T18:28:26.000Z","updated_at":"2021-07-10T04:52:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"9adc72e3-1cf9-4fa1-b744-16e292678ea8","html_url":"https://github.com/ajithvcoder/Session_9_Tuples-NamedTuples","commit_stats":null,"previous_names":["ajithvcoder/session_9_tuples-namedtuples"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajithvcoder/Session_9_Tuples-NamedTuples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_9_Tuples-NamedTuples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_9_Tuples-NamedTuples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_9_Tuples-NamedTuples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_9_Tuples-NamedTuples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajithvcoder","download_url":"https://codeload.github.com/ajithvcoder/Session_9_Tuples-NamedTuples/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajithvcoder%2FSession_9_Tuples-NamedTuples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272144649,"owners_count":24881141,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:37.072Z","updated_at":"2025-09-23T16:29:00.606Z","avatar_url":"https://github.com/ajithvcoder.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Tuples and NamedTuples\n\n**Faker profile with tuple**\n\nGenerate n number of fake profiles and find largest blood group,\n    average age, oldest age, mean geo location with tuples\n\n\n    def genrate_with_faker_tuple(seed_no: int, n: int) -\u003e 'tuple':\n        ...\n        for iter in range(n):\n            PersonN = Person(**fake.profile())\n            list_Person.append(PersonN)\n        ...\n        for person in list_Person:\n            # oldest age \n            Age = datetime.now().year - person.birthdate.year        \n            if oldest_person_age \u003c  Age:                     \n                oldest_person_age = Age\n            # average age\n            averageage +=  Age\n            #mean current location\n            mean_current_location +=  sum(person.current_location)/2\n            #largest blood group\n            if person.blood_group in blood_group:\n                blood_group[person.blood_group] += 1\n            else:\n                blood_group[person.blood_group] = 0\n        largest_blood_group = max(blood_group , key = blood_group.get)    \n        ...\n\nWe are using a specific seed so that we can double check our results when generating fake data. We are using two namedtuples'Person' and 'Calculate'. 'Person' is used as a template to store all the profiles of person. largest_blood_group is calculated using counter , age , average age and mean geo location is calculated in a single iteration. Processing time is calculated\n\n\n**Faker profile with Dictionary**\n\nGenerate n number of fake profiles and find largest blood group,\n    average age, oldest age, mean geo location with dictionary\n\t\n\n    def genrate_with_faker_dict(seed_no: int, n: int) -\u003e 'tuple':\n        ...\n        for iter in range(n):\n            PersonN = dict(zip(person_keys,fake.profile().values()))        \n            list_Person.append(PersonN)\n        ...\n        for person in list_Person:\n            # oldest age \n            Age = datetime.now().year - person[\"birthdate\"].year        \n            if oldest_person_age \u003c  Age:                     \n                oldest_person_age = Age\n\n            # average age\n            averageage +=  Age\n\n            #mean current location\n            mean_current_location +=  sum(person[\"current_location\"])/2\n\n            #largest blood group\n            if person[\"blood_group\"] in blood_group:\n                blood_group[person[\"blood_group\"]] += 1\n            else:\n                blood_group[person[\"blood_group\"]] = 0\n            \n        largest_blood_group = max(blood_group , key = blood_group.get)    \n        ...\n\nWe are using a specific seed so that we can double check our results when generating fake data. We are using two dictionaries 'Person' and 'Calculate'. 'Person' is used as a template to store all the profiles of person. largest_blood_group is calculated using counter , age , average age and mean geo location is calculated in a single iteration. Processing time is calculated\n\nFor 5 iterations Average Processing time of namedtuples  is less than Average processing time of dictionary \n\n- Avg namedtuple 0.026053428649902344\n- Avg dictionary 0.03391456604003906\n\n**Faker Stock exchange**\n\nGenerate n number of stock data and find open, high, close of stock exchange\n\t\n\n    def faker_stock_exchange(seed_num : int, n :int) -\u003e 'tuple':\n        ...\n        for iter in range(n):\n            Stock1 = Stock(*getData())\n            stock_list.append(Stock1)\n        ...\n        start_time = time.perf_counter()\n        stock_exchange = namedtuple(\"StockExchange\",(\"Open\",\"High\", \"Close\", ))\n        stock_exchange.__doc__ = \"Contains total Open, high, close stock exchange details \"    \n        stock_open = 0\n        stock_high = 0\n        stock_close = 0\n        for company in stock_list:\n            stock_open += (company.Open * company.Price)\n            stock_high += (company.High * company.Price)\n            stock_close += (company.Close * company.Price)\n        display_Stock = stock_exchange(stock_open, stock_high, stock_close)\n        stop_time = time.perf_counter()\n        ...\n\nWe are getting random datas for companyname, symbold, price, open, high and close. we are using the price and the stock and calculating the market value of total stock exchage. With that value we are calculatin overall capital when opening, and when its high and at close time.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Fsession_9_tuples-namedtuples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajithvcoder%2Fsession_9_tuples-namedtuples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajithvcoder%2Fsession_9_tuples-namedtuples/lists"}