Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • icon picker
        Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

Day 3 : Array + String

🟢 Day 3 — Working With Many Values (Lists & Strings)

1️⃣ Why Do We Need This?

Until now, we worked like this:
a = 10
b = 20
c = 30

Real-life problem

What if:
You have marks of 50 students
You have prices of 100 products
You have names of 1000 users
Creating separate variables is:
Impossible to manage
Error-prone
Not scalable
💡 When you have many similar values, you use a collection.

2️⃣ Introducing Lists — One Variable, Many Values

Real-world analogy

Think of a train:
One train (list)
Many compartments (elements)
Each compartment has a number (index)

Creating a List

numbers = [10, 20, 30, 40]
Here:
numbers → list
10, 20, 30, 40 → elements

3️⃣ Indexing — How to Access Elements

print(numbers[0]) # 10
print(numbers[1]) # 20

Important Rule (VERY IMPORTANT)

Python starts counting from 0, not 1.
Index: 0 1 2 3
Value: 10 20 30 40

Why Index Starts From 0?

You don’t need to memorize why, just accept:
Index = how far from the start
First element is 0 steps away.

4️⃣ What Happens If Index Does Not Exist?

print(numbers[10])
❌ Program crashes.
Why?
Python does not guess
It only accesses what exists
🧠 The computer never assumes. It either finds something or fails.

5️⃣ Looping Over a List (MOST USED PATTERN)

Instead of accessing elements one by one:
print(numbers[0])
print(numbers[1])
Use a loop:
for num in numbers:
print(num)

How Computer Thinks

Take first element → num
Print it
Take next element
Stop when list ends

6️⃣ Lists + Logic = Real Programs

Example: Find Largest Number

numbers = [10, 45, 23, 89, 5]

largest = numbers[0]

for num in numbers:
if num > largest:
largest = num

print(largest)

How to Think (THIS IS IMPORTANT)

Assume first number is largest
Compare every number
Update when you find bigger
🧠 This thinking pattern is used everywhere in programming.

7️⃣ Strings Are Also Collections 🤯

You already know strings:
name = "python"
But a string is actually:
'p' 'y' 't' 'h' 'o' 'n'

Looping Over String

for ch in name:
print(ch)
💡 Strings behave like lists of characters.

8️⃣ Length of List or String

print(len(numbers))
print(len(name))
len() tells how many items
Works for list and string

9️⃣ Counting Pattern (Extremely Important)

Example: Count Even Numbers

count = 0

for num in numbers:
if num % 2 == 0:
count += 1

print(count)

Thinking Pattern

Start counter at 0
Increase when condition matches
Print at end
🧠 Counting is one of the most used patterns in programming.

🔁 Key Thinking Patterns Learned Today

Whenever you see a collection, ask:
Do I need to check every element?
Do I need to remember something while looping?
Do I need to compare values?
Do I need to count or accumulate?

⚠️ Common Beginner Mistakes

Using wrong index
Modifying list incorrectly
Forgetting loop
Confusing index and value
Assuming list has unlimited size

🧪 Practice Questions (Very Important)

Do not rush. Think → write steps → then code.

Q1

Create a list of 5 numbers and print all elements.

Q2

Find the smallest number in a list.

Q3

Count how many even numbers are in a list.

Q4

Check if a given number exists in a list.
Example:
List: [1, 2, 3, 4]
Input: 3
Output: Found

Q5

Reverse a list without using built-in reverse.

Q6

Count number of vowels in a string.
Example:
Input: "programming"
Output: 3

Q7 (Thinking Question)

What happens if the list is empty? How should your program behave?

🔑 HINTS (Read Together, Only If Stuck)

Assume first element for min/max
Use % 2 for even check
Use a flag variable (found = False)
For reverse: create a new list or loop backwards
Vowels: a, e, i, o, u
Always think about empty input

✅ What You Should Be Able to Do Now

After Day 3, you should:
Store multiple values in a list
Loop over collections
Apply logic to each element
Process strings as character lists
Build real data-processing logic

🧠 Reflection Questions (Answer in Words)

Why do we use lists instead of many variables?
What is difference between index and value?
Why do we assume first element for max/min?
Why does string behave like list?

⭐ Golden Rule from Day 3

Real programs are not about single values. They are about collections of values.
If you say “Continue with Day 4”, next we’ll cover:
Functions
Reuse & clean thinking
Breaking problems into pieces
First step toward real software design
One day at a time.
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.