Python | Algorithms | Data Structures | Cyber ​​Security | Networks
38.6K subscribers
779 photos
23 videos
21 files
714 links
This channel is for Programmers, Coders, Software Engineers.

1) Python
2) django
3) python frameworks
4) Data Structures
5) Algorithms
6) DSA

Admin: @Hussein_Sheikho

Ad & Earn money form your channel:
https://telega.io/?r=nikapsOH
Download Telegram
Topic: Linked Lists in Python – Part 1: Introduction and Singly Linked List Basics

---

What is a Linked List?

• A linked list is a linear data structure where each element (called a node) contains:

• The data value.
• A pointer (or reference) to the next node.

• Unlike arrays, linked lists don’t require contiguous memory and can grow dynamically.

---

Why Use Linked Lists?

Efficient insertions/deletions at the beginning or middle.
No need for pre-defining size, unlike arrays.
• Used in memory-efficient applications like OS kernels, compilers, and real-time systems.

---

Types of Linked Lists

Singly Linked List – Each node points to the next.
Doubly Linked List – Nodes have next and previous pointers.
Circular Linked List – The last node points back to the head.

---

Basic Structure of a Node

class Node:
def __init__(self, data):
self.data = data
self.next = None


---

Building a Singly Linked List

class LinkedList:
def __init__(self):
self.head = None

def append(self, data):
new_node = Node(data)

if not self.head:
self.head = new_node
return

current = self.head
while current.next:
current = current.next
current.next = new_node


---

Traversing the List

def display(self):
current = self.head
while current:
print(current.data, end=" -> ")
current = current.next
print("None")


Usage:

ll = LinkedList()
ll.append(10)
ll.append(20)
ll.append(30)
ll.display() # Output: 10 -> 20 -> 30 -> None


---

Inserting at the Beginning

def insert_at_beginning(self, data):
new_node = Node(data)
new_node.next = self.head
self.head = new_node


---

Summary

• A singly linked list stores data as a sequence of nodes linked by references.

• Supports dynamic memory usage, fast insertions, and flexible resizing.

• The key is managing node connections safely and efficiently.

---

Exercise

• Implement a method length() that returns the number of nodes in the list.

---

#DataStructures #LinkedList #DSA #Python #CodingBasics

https://t.iss.one/DataScience4
3
Topic: Python Functions – Part 1 of 3: Basics, Syntax, and Parameters (Long Lesson)

---

### 1. What is a Function in Python?

A function is a reusable block of code that performs a specific task. Functions help:

• Avoid code duplication
• Improve code readability
• Enable modular programming

---

### 2. Why Use Functions?

Reusability – Write once, use many times
Modularity – Split large tasks into smaller blocks
Debuggability – Easier to test/debug small units
Abstraction – Hide complex logic behind a name

---

### 3. Function Syntax

def function_name(parameters):
# block of code
return result


---

### 4. Creating a Simple Function

def greet():
print("Hello, welcome to Python functions!")

greet() # Calling the function


---

### 5. Function with Parameters

def greet_user(name):
print(f"Hello, {name}!")

greet_user("Hussein")


---

### 6. Function with Return Value

def add(a, b):
return a + b

result = add(10, 5)
print(result) # Output: 15


---

### 7. Positional vs Keyword Arguments

def student_info(name, age):
print(f"Name: {name}, Age: {age}")

student_info("Ali", 22) # Positional
student_info(age=22, name="Ali") # Keyword


---

### 8. Default Parameter Values

def greet(name="Guest"):
print(f"Hello, {name}!")

greet() # Output: Hello, Guest!
greet("Hussein") # Output: Hello, Hussein!


---

### 9. Variable Number of Arguments

#### \*args – Multiple positional arguments:

def sum_all(*numbers):
total = 0
for num in numbers:
total += num
return total

print(sum_all(1, 2, 3, 4)) # Output: 10


#### \*\*kwargs – Multiple keyword arguments:

def print_details(**info):
for key, value in info.items():
print(f"{key}: {value}")

print_details(name="Ali", age=24, country="Egypt")


---

### **10. Scope of Variables**

#### Local vs Global Variables

x = "global"

def func():
x = "local"
print(x)

func() # Output: local
print(x) # Output: global


Use global keyword if you want to modify a global variable inside a function.

---

### 11. Docstrings (Function Documentation)

def square(n):
"""Returns the square of a number."""
return n * n

print(square.__doc__) # Output: Returns the square of a number.


---

### 12. Best Practices

• Use descriptive names for functions
• Keep functions short and focused
• Avoid side effects unless needed
• Add docstrings for documentation

---

### Exercise

• Create a function that takes a list and returns the average
• Create a function that takes any number of scores and returns the highest
• Create a function with default arguments for greeting a user by name and language

---

#Python #Functions #CodingBasics #ModularProgramming #CodeReuse #PythonBeginners

https://t.iss.one/DataScience4
6👏2