{"id":25933460,"url":"https://github.com/hcvazquez/python-basic-data-structures","last_synced_at":"2026-06-08T19:03:17.190Z","repository":{"id":116217406,"uuid":"188748995","full_name":"hcvazquez/python-basic-data-structures","owner":"hcvazquez","description":"Python basic data structures","archived":false,"fork":false,"pushed_at":"2019-05-30T02:57:49.000Z","size":11,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-01T20:38:56.402Z","etag":null,"topics":["data-structures","programming-language","python"],"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/hcvazquez.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-05-27T01:10:38.000Z","updated_at":"2019-06-06T04:59:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"59181505-4d39-482d-baec-7e559db5c019","html_url":"https://github.com/hcvazquez/python-basic-data-structures","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hcvazquez/python-basic-data-structures","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hcvazquez%2Fpython-basic-data-structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hcvazquez%2Fpython-basic-data-structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hcvazquez%2Fpython-basic-data-structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hcvazquez%2Fpython-basic-data-structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hcvazquez","download_url":"https://codeload.github.com/hcvazquez/python-basic-data-structures/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hcvazquez%2Fpython-basic-data-structures/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34075990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-08T02:00:07.615Z","response_time":111,"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":["data-structures","programming-language","python"],"created_at":"2025-03-04T00:53:57.959Z","updated_at":"2026-06-08T19:03:17.184Z","avatar_url":"https://github.com/hcvazquez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Basic Data Structures\n\nPython has four basic inbuilt data structures namely Lists, Dictionary, Tuple and Set. These almost cover 80% of the our real world data structures. This article will cover the above mentioned topics.\n\n## Lists\n\nLists : Lists in Python are one of the most versatile collection object types available. The other two types are dictionaries and tuples, but they are really more like variations of lists.\n* Python lists do the work of most of the collection data structures found in other languages and since they are built-in, you don’t have to worry about manually creating them.\n* Lists can be used for any type of object, from numbers and strings to more lists.\n* They are accessed just like strings (e.g. slicing and concatenation) so they are simple to use and they’re variable length, i.e. they grow and shrink automatically as they’re used.\n* In reality, Python lists are C arrays inside the Python interpreter and act just like an array of pointers.\n\n```python\n# Python program to illustrate \n# A simple list \n  \n# Declaring a list \nL = [1, \"a\" , \"string\" , 1+2] \nprint L \n  \n# add 6 to the above list \nL.append(6) \nprint L \n  \n# pop deletes the last element of the list \nL.pop() \nprint L \n  \nprint L[1]\n```\nOutput:\n```python\n[1, 'a', 'string', 3]\n[1, 'a', 'string', 3, 6]\n[1, 'a', 'string', 3]\na\n```\n\nThere are various Functions that can be carried out on lists like append(), extend(), reverse(), pop() etc. To read more about lists methods you can click here.\n\n## Dictionary\n\nIn python, dictionary is similar to hash or maps in other languages. It consists of key value pairs. The value can be accessed by unique key in the dictionary.\n* Keys are unique \u0026 immutable objects.\n* Syntax:\n\u003e dictionary = {\"key name\": value}\n\n```python\n# Python program to illustrate \n# dictionary \n  \n# Create a new dictionary  \nd = dict() # or d = {} \n  \n# Add a key - value pairs to dictionary \nd['xyz'] = 123\nd['abc'] = 345\n  \n# print the whole dictionary \nprint d \n  \n# print only the keys \nprint d.keys() \n  \n# print only values \nprint d.values() \n  \n# iterate over dictionary  \nfor i in d : \n    print \"%s %d\" %(i, d[i]) \n  \n# another method of iteration \nfor index, value in enumerate(d): \n    print index, value , d[value] \n  \n# check if key exist \nprint 'xyz' in d \n  \n# delete the key-value pair \ndel d['xyz'] \n  \n# check again  \nprint \"xyz\" in d\n``` \nOutput:\n```python\n{'xyz': 123, 'abc': 345}\n['xyz', 'abc']\n[123, 345]\nxyz 123\nabc 345\n0 xyz 123\n1 abc 345\nTrue\nFalse\n```\n\n## Tuples\n\nPython tuples work exactly like Python lists except they are immutable, i.e. they can’t be\nchanged in place. They are normally written inside parentheses to distinguish them from lists (which use square brackets), but as you’ll see, parentheses aren’t always necessary. Since tuples are immutable, their length is fixed. To grow or shrink a tuple, a new tuple must be created.\nHere’s a list of commonly used tuples:\n\n\u003e () An empty tuple\\\n\u003e t1 = (0, ) A one-item tuple (not an expression)\\\n\u003e t2 = (0, 1, 2, 3) A four-item tuple\\\n\u003e t3 = 0, 1, 2, 3 Another four-item tuple (same as prior line, just minus the parenthesis)\\\n\u003e t3 = (‘abc’, (‘def’, ‘ghi’)) Nested tuples\\\n\u003e t1[n], t3[n][j] Index\\\n\u003e t1[i:j], Slice\\\n\u003e len(tl) Length\n\n\n```python\n# Python program to illustrate \n# tuple \ntup = (1, \"a\", \"string\", 1+2) \nprint tup \nprint tup[1]\n``` \nOutput:\n```python\n(1, 'a', 'string', 3)\na\n```\n\n## Sets\n\nUnordered collection of unique objects.\n* Set operations such as union (|) , intersection(\u0026), difference(-) can be applied on a set.\n* Sets are immutable i.e once created further data can’t be added to them\n* () are used to represent a set.Objects placed inside these brackets would be treated as a set.\n\n```python\n# Python program to demonstrate working of \n# Set in Python \n   \n# Creating two sets \nset1 = set() \nset2 = set() \n   \n# Adding elements to set1 \nfor i in range(1, 6): \n    set1.add(i) \n   \n# Adding elements to set2 \nfor i in range(3, 8): \n    set2.add(i) \n   \nprint(\"Set1 = \", set1) \nprint(\"Set2 = \", set2) \nprint(\"\\n\")\n```\nOutput:\n```python\n('Set1 = ', set([1, 2, 3, 4, 5]))\n('Set2 = ', set([3, 4, 5, 6, 7]))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhcvazquez%2Fpython-basic-data-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhcvazquez%2Fpython-basic-data-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhcvazquez%2Fpython-basic-data-structures/lists"}