-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_structures.py
More file actions
61 lines (46 loc) · 1.33 KB
/
data_structures.py
File metadata and controls
61 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
data_structures.py
Demonstrates the core data structures in Python:
list, tuple, set, and dictionary with practical examples.
"""
# List (Ordered and Mutable)
skills = ["Python", "HTML", "Git"]
skills.append("AI Basics")
print("List Example:")
print("Skills:", skills)
print("First skill:", skills[0])
print("Total skills:", len(skills))
# Tuple (Ordered and Immutable)
coordinates = (10, 20)
print("\nTuple Example:")
print("Coordinates:", coordinates)
print("X value:", coordinates[0])
print("Y value:", coordinates[1])
# Set (Unordered and Unique Values)
unique_numbers = {1, 2, 3, 3, 4, 5, 5}
print("\nSet Example:")
print("Unique numbers:", unique_numbers)
unique_numbers.add(6)
print("After adding 6:", unique_numbers)
# Dictionary (Key-Value Pairs)
user_profile = {
"name": "Subham",
"age": 22,
"skills": skills,
"is_active": True
}
print("\nDictionary Example:")
print("User Profile:", user_profile)
print("User Name:", user_profile["name"])
print("User Skills:", user_profile["skills"])
# Updating dictionary value
user_profile["age"] = 23
print("Updated Age:", user_profile["age"])
# Looping through list
print("\nLooping through list:")
for skill in skills:
print(skill)
# Looping through dictionary
print("\nLooping through dictionary:")
for key, value in user_profile.items():
print(f"{key} : {value}")