Data Structures in Python
Python Made Easy - (Article 9) Telugu Explanation
What are Data Structures?
Data Structures ante - data ni store, manage, access cheyyadaniki use chese containers.
Example:
Imagine nenu oka cupboard lo items pettaali anukunta -
- 1st shelf lo books,
- 2nd shelf lo clothes,
- 3rd shelf lo tools.
Ippudu cupboard lo anni neatly arrange ayyi untayi - whenever needed, manam easy ga item find cheyyachu.
Get D Naresh’s stories in your inbox
Join Medium for free to get updates from this writer.
Alage Python lo kooda, data ni store cheyyadaniki different containers unnayi:
➡ List - items order lo untayi, change cheyyachu.
➡ Tuple - order untundi, kaani change cheyyalem.
➡ Set - duplicates undavu, order guarantee ledu.
➡ Dictionary - key:value pairs lo data untundi (like name: “Naresh”, age: 25).
Types of Data Structures in Python
1. List
List ante - multiple values ni [square brackets] lo store chestam.
Example:
fruits = ["apple", "banana", "cherry"]
print(fruits)Output:
['apple', 'banana', 'cherry']Accessing List Items (Indexing)
print(fruits[0]) # apple
print(fruits[1]) # bananaNegative Indexing
print(fruits[-1]) # cherry
print(fruits[-2]) # bananaSlicing (Range of Items)
print(fruits[0:2])Output:
['apple', 'banana']Changing Values
fruits[1] = "mango"
print(fruits)Output:
['apple', 'mango', 'cherry']Adding Items
fruits.append("orange")
print(fruits)Output:
['apple', 'mango', 'cherry', 'orange']Removing Items
fruits.remove("mango")
print(fruits)Loop Through List
for item in fruits:
print(item)Example Mini Program
Print all even numbers from a list
numbers = [1, 2, 3, 4, 5, 6]
for n in numbers:
if n % 2 == 0:
print(n)Output:
2
4
62. Tuple
Tuple ante - unchangeable list.
Use (round brackets).
colors = ("red", "green", "blue")
print(colors)Output:
('red', 'green', 'blue')Access Tuple Items
print(colors[0]) # redYou can’t change or add items in tuple.
Example
student = ("Naresh", 25, "Python")
for item in student:
print(item)Output:
Naresh
25
Python3. Set
Set ante - unique values collection.
Use {curly braces}.
Duplicates automatically remove avutayi.
nums = {1, 2, 3, 3, 4, 5}
print(nums)Output:
{1, 2, 3, 4, 5}Add / Remove Items
nums.add(6)
nums.remove(2)
print(nums)Loop Through Set
for n in nums:
print(n)Set Operations (Union, Intersection)
a = {1, 2, 3}
b = {3, 4, 5}print(a | b) # Union
print(a & b) # IntersectionOutput:
{1, 2, 3, 4, 5}
{3}4. Dictionary
Dictionary ante - key: value pairs collection.
Use {curly braces} with : between key and value.
person = {"name": "Naresh", "age": 25, "city": "Hyderabad"}
print(person)Output:
{'name': 'Naresh', 'age': 25, 'city': 'Hyderabad'}Access Values
print(person["name"])Output:
NareshAdd / Update Values
person["email"] = "naresh@example.com"
person["age"] = 26
print(person)Remove Items
person.pop("city")
print(person)Loop Through Dictionary
for key, value in person.items():
print(key, ":", value)Output:
name : Naresh
age : 26
email : naresh@example.comString Operations (Bonus)
Strings kuda chinna data structure laaga untundi.
Text ni " " lo store chestam.
name = "Naresh"
print(name[0]) # N
print(name[1:4]) # are
print(name.lower()) # naresh
print(name.upper()) # NARESH
print(len(name)) # 6Loop Through String
for ch in name:
print(ch)Check Substring
print("resh" in name) # True
print("xyz" not in name) # TrueExample Mini Program
text = "python is easy"
count = 0
for ch in text:
if ch == 'a':
count += 1
print("Number of 'a's:", count)Output:
Number of 'a's: 1Key Takeaways
Practice Questions
- Create a list of your 5 favorite movies and print only the first 3.
- Create a tuple of student details (name, age, grade).
- Create a set of fruits and perform union and intersection.
- Create a dictionary of 3 friends and their favorite colors.
- Write a program to count vowels in a string.
I have added more methods and detailed explanations.
Click here 👉 To explore the complete structured guide on Python Data Structures.
Previous & Next
Next Article: 👉10. Strings and String Operations in Python
Previous Article: 👉8. Star Patterns and Logical Programs









