Learn Python Coding
38.7K subscribers
1.06K photos
37 videos
24 files
853 links
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
πŸ“š Python-Based Data Structures and Algorithms (2023)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/974

πŸ’¬ Tags: #dsa

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘4
πŸ“š Data Structures and Algorithms with Python (2023)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1054

πŸ’¬ Tags: #dsa

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘6
πŸ“š Data structures and Algorithms with python (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1193

πŸ’¬ Tags: #DSA

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘12πŸ’―1
πŸ“š Data Structures & Algorithms in Go (2018)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1244

πŸ’¬ Tags: #DSA #Go

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘5
πŸ“š Data Structures and Algorithms with Go (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1410

πŸ’¬ Tags: #DSA #GO

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘10
πŸ“š Introductory Data Structures and Algorithms (2024)

1️⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2️⃣ Download Book: https://t.me/c/1854405158/1453

πŸ’¬ Tags: #DSA

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11❀2
πŸ“š Data Structures the Fun Way (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1611

πŸ’¬ Tags: #DSA

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘9❀2
πŸ“š Python Exercises with Data Structures and Algorithms (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1646

πŸ’¬ Tags: #DSA

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘12
πŸ“š Algorithms and Data Structures with Python (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1676

πŸ’¬ Tags: #DSA

πŸ‘‰ BEST DATA SCIENCE CHANNELS ON TELEGRAM πŸ‘ˆ
πŸ‘7❀2
πŸ“š Data Structure and Algorithm (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1818

πŸ’¬ Tags: #DSA

USEFUL CHANNELS FOR YOU
πŸ‘1
πŸ“š Data Structure in Python (2024)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1827

πŸ’¬ Tags: #dsa

USEFUL CHANNELS FOR YOU
πŸ“š Python Data Structures and Algorithms (2017)

1⃣ Join Channel Download:
https://t.me/+MhmkscCzIYQ2MmM8

2⃣ Download Book: https://t.me/c/1854405158/1954

πŸ’¬ Tags: #DSA

USEFUL CHANNELS FOR YOU
πŸ‘2
Open Guide to Data Structures and Algorithms

A must-read for anyone starting their journey in computer science and programming. This open-access book offers a clear, beginner-friendly introduction to the core concepts of data structures and algorithms, with simple explanations and practical examples. Whether you're a student or a self-learner, this guide is a solid foundation to build your DSA knowledge. Highly recommended for those who want to learn efficiently and effectively.

Read it here:
https://pressbooks.palni.org/anopenguidetodatastructuresandalgorithms

#DSA #Algorithms #DataStructures #ProgrammingBasics #CSforBeginners #OpenSourceLearning #CodingJourney #TechEducation #ComputerScience #PythonBeginners

⚑️ BEST DATA SCIENCE CHANNELS ON TELEGRAM 🌟
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘4πŸ”₯2
"Data Structures & Algorithms using Python"

This book covers all types of data structures from Arrays to Graphs. Simple to complex algorithms. πŸ’― FREE.

Download it: https://donsheehy.github.io/datastructures/fullbook.pdf

#python #OOP #DSA

βœ‰οΈ Our Telegram channels: https://t.me/addlist/0f6vfFbEMdAwODBk

πŸ“± Our WhatsApp channel: https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
πŸ‘4❀1
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.me/DataScience4
❀3
Topic: Linked Lists in Python – Part 2: Insertion, Deletion, and Search Operations

---

Recap from Part 1

β€’ A singly linked list consists of nodes, where each node holds data and a pointer to the next node.

β€’ We've implemented basic append and display functions.

Now we’ll explore insertion at specific positions, deletion, and searching.

---

1. Insert at a Specific Position

def insert_at_position(self, index, data):
if index < 0:
raise IndexError("Index cannot be negative")

new_node = Node(data)

if index == 0:
new_node.next = self.head
self.head = new_node
return

current = self.head
for _ in range(index - 1):
if not current:
raise IndexError("Index out of bounds")
current = current.next

new_node.next = current.next
current.next = new_node


---

2. Delete a Node by Value

def delete_by_value(self, value):
if not self.head:
return

if self.head.data == value:
self.head = self.head.next
return

current = self.head
while current.next and current.next.data != value:
current = current.next

if current.next:
current.next = current.next.next


---

3. Delete a Node by Index

def delete_by_index(self, index):
if index < 0:
raise IndexError("Index cannot be negative")

if not self.head:
raise IndexError("List is empty")

if index == 0:
self.head = self.head.next
return

current = self.head
for _ in range(index - 1):
if not current.next:
raise IndexError("Index out of bounds")
current = current.next

if current.next:
current.next = current.next.next


---

4. Search for an Element

def search(self, value):
current = self.head
index = 0
while current:
if current.data == value:
return index
current = current.next
index += 1
return -1 # Not found


---

5. Complete Class with All Methods

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

def append(self, data): ...
def display(self): ...
def insert_at_position(self, index, data): ...
def delete_by_value(self, value): ...
def delete_by_index(self, index): ...
def search(self, value): ...


*(You can reuse the method definitions above.)*

---

Summary

β€’ You can manipulate linked lists with insertions and deletions at any position.

β€’ Searching through a singly linked list is O(n).

β€’ Always check for edge cases: empty list, index bounds, and duplicates.

---

Exercise

β€’ Write a method reverse() that reverses the linked list in-place and test it on a list of 5+ elements.

---

#DSA #LinkedList #Python #Insertion #Deletion #Search

https://t.me/DataScience4
❀2
Topic: Linked Lists in Python – Part 3: Reversing, Detecting Loops, and Middle Node

---

In this part, we’ll explore advanced operations that are frequently asked in coding interviews using singly linked lists.

---

1. Reverse a Linked List (Iterative)

def reverse(self):
prev = None
current = self.head
while current:
next_node = current.next
current.next = prev
prev = current
current = next_node
self.head = prev


β€’ Time Complexity: O(n)
β€’ Space Complexity: O(1)

---

2. Find the Middle of the Linked List

β€’ Use the slow and fast pointer approach.

def find_middle(self):
slow = fast = self.head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
return slow.data if slow else None


---

3. Detect a Loop in the Linked List

β€’ Use Floyd’s Cycle Detection Algorithm (a.k.a. Tortoise and Hare).

def has_loop(self):
slow = fast = self.head
while fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False


---

4. Find the N-th Node from the End

def nth_from_end(self, n):
first = self.head
second = self.head

for _ in range(n):
if not first:
return None
first = first.next

while first:
first = first.next
second = second.next

return second.data


---

5. Full Example: Testing All Methods

ll = LinkedList()
for value in [10, 20, 30, 40, 50]:
ll.append(value)

ll.display()
ll.reverse()
ll.display()
print("Middle:", ll.find_middle())
print("Has Loop?", ll.has_loop())
print("3rd from End:", ll.nth_from_end(3))


---

Summary

β€’ Use pointer manipulation for efficient algorithms in linked lists.

β€’ Common techniques:
β€’ Fast/slow pointers
β€’ Reversal by in-place re-linking
β€’ Two-pointer gap approach for nth from end

---

Exercise

β€’ Write a method is_palindrome() that checks if the linked list reads the same forwards and backwards (without converting it to a list or using extra space).

---

#DSA #LinkedList #ReverseList #LoopDetection #TwoPointerTechnique

https://t.me/DataScience4
❀5
Topic: Linked Lists in Python – Part 4: Merging, Sorting, and Advanced Interview Problems

---

In this final part of the Linked List series, we’ll tackle more advanced and practical use cases like merging sorted lists, sorting a linked list, and interview-level challenges.

---

1. Merging Two Sorted Linked Lists

def merge_sorted_lists(l1, l2):
dummy = Node(0)
tail = dummy

while l1 and l2:
if l1.data < l2.data:
tail.next = l1
l1 = l1.next
else:
tail.next = l2
l2 = l2.next
tail = tail.next

tail.next = l1 or l2
return dummy.next


---

2. Sorting a Linked List (Merge Sort – O(n log n))

def merge_sort(head):
if not head or not head.next:
return head

# Split list
slow, fast = head, head.next
while fast and fast.next:
slow = slow.next
fast = fast.next.next

mid = slow.next
slow.next = None

left = merge_sort(head)
right = merge_sort(mid)

return merge_sorted_lists(left, right)


β€’ Attach this to your LinkedList class to sort self.head.

---

3. Removing Duplicates from a Sorted List

def remove_duplicates(self):
current = self.head
while current and current.next:
if current.data == current.next.data:
current.next = current.next.next
else:
current = current.next


---

4. Intersection Point of Two Linked Lists

def get_intersection_node(headA, headB):
if not headA or not headB:
return None

a, b = headA, headB
while a != b:
a = a.next if a else headB
b = b.next if b else headA
return a # Can be None or the intersecting node


---

5. Flatten a Multilevel Linked List

Imagine a list where each node has next and child pointers. Recursively flatten:

def flatten(node):
if not node:
return None

next_node = node.next
if node.child:
child_tail = flatten(node.child)
node.next = node.child
node.child = None
child_tail.next = flatten(next_node)
return child_tail if child_tail.next else child_tail
else:
node.next = flatten(next_node)
return node


---

Summary

β€’ You now know how to merge, sort, and deduplicate linked lists.

β€’ Techniques like merge sort, two-pointer traversal, and recursive flattening are essential for mastering linked lists.

β€’ These problems are frequently asked in interviews at top tech companies.

---

Exercise

β€’ Given two unsorted linked lists, write a function that returns a new linked list containing only the elements present in both lists (intersection), without using extra space or sets.

---

#DSA #LinkedList #MergeSort #AdvancedDSA #CodingInterview

https://t.me/DataScience4
❀2
Topic: Data Structures – Trees – Part 1 of 4: Introduction and Binary Trees

---

### 1. What is a Tree in Data Structures?

A tree is a non-linear hierarchical data structure consisting of nodes connected by edges. It's widely used in real-world applications like:

β€’ File systems
β€’ Databases (e.g., B-Trees)
β€’ Compilers (parse trees)
β€’ Artificial intelligence (decision trees)

---

### 2. Terminologies in Trees

β€’ Node: Basic unit of a tree
β€’ Root: Topmost node (only one)
β€’ Parent/Child: A node that connects to another below/above
β€’ Leaf: A node with no children
β€’ Edge: Connection between parent and child
β€’ Subtree: Any child node and its descendants
β€’ Depth: Distance from the root to a node
β€’ Height: Longest path from a node to a leaf
β€’ Degree: Number of children a node has

---

### 3. Binary Tree Basics

A Binary Tree is a tree in which each node has at most two children, referred to as:

β€’ Left child
β€’ Right child

#### Real-life example:

Imagine a family tree where each person can have two children.

---

### 4. Types of Binary Trees

β€’ Full Binary Tree – every node has 0 or 2 children
β€’ Perfect Binary Tree – all internal nodes have 2 children, and all leaves are at the same level
β€’ Complete Binary Tree – all levels are filled except possibly the last, which is filled from left to right
β€’ Skewed Tree – all nodes only have one child (left or right)
β€’ Balanced Binary Tree – the height difference of left and right subtrees is minimal

---

### 5. Binary Tree Representation in Python

Using Class & Object:

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

# Example
root = Node(1)
root.left = Node(2)
root.right = Node(3)


---

### 6. Tree Traversals

Tree traversal means visiting all the nodes of a tree in a specific order.

β€’ Inorder (LNR)
β€’ Preorder (NLR)
β€’ Postorder (LRN)
β€’ Level Order (BFS using queue)

#### Example – Inorder Traversal (Left β†’ Root β†’ Right):

def inorder(root):
if root:
inorder(root.left)
print(root.data, end=" ")
inorder(root.right)


---

### 7. Build a Simple Binary Tree and Traverse It

# Tree Structure:
# 1
# / \
# 2 3
# / \
# 4 5

root = Node(1)
root.left = Node(2)
root.right = Node(3)
root.left.left = Node(4)
root.left.right = Node(5)

print("Inorder Traversal:")
inorder(root) # Output: 4 2 5 1 3


---

### 8. Applications of Binary Trees

β€’ Expression evaluation
β€’ Search algorithms (Binary Search Trees)
β€’ Priority queues (Heaps)
β€’ Huffman encoding trees (data compression)
β€’ Syntax trees in compilers

---

### 9. Key Characteristics

β€’ Recursive nature makes tree problems suitable for recursion
β€’ Not sequential – can't be represented with only arrays or lists
β€’ Memory-efficient using pointers in linked structure

---

### 10. Summary

β€’ Trees are hierarchical and non-linear
β€’ Binary trees limit nodes to max 2 children
β€’ Various types of binary trees serve different use cases
β€’ Tree traversal is fundamental for solving tree problems

---

### Exercise

Create a class-based binary tree and implement:
β€’ Inorder, Preorder, and Postorder traversals
β€’ Function to count total nodes and leaf nodes

---

#DSA #BinaryTree #DataStructures #Python #TreeTraversal

https://t.me/DataScience4
❀8