Skip to content

data structure has been added! #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 02-control-flow/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Control Flow in Python

## Introduction

In this section, we will explore the control flow mechanisms in Python, including conditional statements and loops.

## 1. Condition
In Python, we use `if`, `elif`, and `else` statements to implement conditional logic.

## 2. Control Flow
Loops are used to execute a block of code repeatedly until a certain condition is met.
16 changes: 16 additions & 0 deletions 02-control-flow/conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def check_number(num):
"""Check if a number is positive, negative, or zero."""
if num > 0:
return "The number is positive."
elif num < 0:
return "The number is negative."
else:
return "The number is zero."
number = 10
print(f"Number: {number} - {check_number(number)}")

number = -5
print(f"Number: {number} - {check_number(number)}")

number = 0
print(f"Number: {number} - {check_number(number)}")
10 changes: 10 additions & 0 deletions 02-control-flow/loops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fruits = ["apple", "banana", "cherry"]
print("Fruits in the list:")
for fruit in fruits:
print(fruit)

count = 1
print("\nCounting from 1 to 5:")
while count <= 5:
print(count)
count += 1
38 changes: 38 additions & 0 deletions 03-data-structures/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
We will explore four fundamental data structures available in Python: lists, tuples, dictionaries, and sets. Understanding these data structures is essential for effective data management and manipulation in Python programming.

## 1. Lists

Lists are ordered collections that can hold multiple items of various types. They are mutable, meaning you can change their contents after they are created.

### Features
- **Ordered**: Items have a defined order and maintain that order.
- **Mutable**: You can add, remove, or modify items.
- **Indexed**: Items are accessed by their index, starting from 0.

## 2. Tuples

Tuples are ordered collections similar to lists but are immutable, which means once they are created, their contents cannot be changed.

### Features
- **Ordered**: Items have a defined order.
- **Immutable**:We cannot add, modify, or remove items after creation.
- **Indexed**: Items are accessed by their index, starting from 0.

## 3. Dictionaries

Dictionaries are unordered collections of key-value pairs. Each key is unique and is used to access the corresponding value.

### Features
- **Unordered**: Items do not maintain a specific order.
- **Mutable**: You can add, modify, or remove key-value pairs.
- **Key-Value Pair**: Each item consists of a key and a corresponding value.


## 4. Sets

Sets are unordered collections of unique elements. They are useful for operations such as membership testing, eliminating duplicates, and performing set operations.

### Features
- **Unordered**: Items do not maintain any specific order.
- **Mutable**: You can add or remove items, but items must be unique.
- **Unique Elements**: Duplicate elements are automatically removed.
20 changes: 20 additions & 0 deletions 03-data-structures/dictionaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

person = {
"name": "Alice",
"age": 30,
"city": "New York"
}

print("Name:", person["name"])

person["email"] = "[email protected]"
print("Dictionary after adding an email:", person)

del person["city"]
print("Dictionary after removing city:", person)

print("Dictionary keys and values:")
for key, value in person.items():
print(f"{key}: {value}")

print("Email:", person.get("email", "Not found"))
16 changes: 16 additions & 0 deletions 03-data-structures/lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fruits = ["apple", "banana", "cherry"]

print("First fruit:", fruits[0])

fruits.append("date")
print("List after adding a fruit:", fruits)

fruits.remove("banana")
print("List after removing a fruit:", fruits)

print("All fruits in the list:")
for fruit in fruits:
print(fruit)


print("First two fruits:", fruits[:2])
22 changes: 22 additions & 0 deletions 03-data-structures/sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

numbers = {1, 2, 3, 4, 5}

numbers.add(6)
print("Set after adding an element:", numbers)

numbers.remove(3)
print("Set after removing an element:", numbers)

numbers.add(5)
print("Set after adding a duplicate element:", numbers)

print("All numbers in the set:")
for number in numbers:
print(number)

set_a = {1, 2, 3}
set_b = {3, 4, 5}

print("Union of sets:", set_a | set_b)
print("Intersection of sets:", set_a & set_b)
print("Difference of sets:", set_a - set_b)
10 changes: 10 additions & 0 deletions 03-data-structures/tuples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coordinates = (10, 20, 30)

print("First coordinate:", coordinates[0])


print("All coordinates:")
for coordinate in coordinates:
print(coordinate)

print("First two coordinates:", coordinates[:2])