Python Intermediate Guide
Step 16: List Comprehensions
Example:
nums = [1, 2, 3, 4, 5]
squares = [x**2 for x in nums]
print(squares)
Step 17: Lambda Functions
Example:
double = lambda x: x * 2
print(double(5))
Step 18: Map, Filter, Reduce
Example:
nums = [1, 2, 3, 4, 5]
print(list(map(lambda x: x*2, nums)))
print(list(filter(lambda x: x%2==0, nums)))
from functools import reduce
print(reduce(lambda a,b: a+b, nums))
Step 19: Working with JSON
Example:
import json
person = {"name": "Alice", "age": 20}
json_str = [Link](person)
print(json_str)
data = [Link](json_str)
print(data["name"])
Step 20: Random Module
Example:
import random
print([Link](1, 10))
print([Link](["red", "blue", "green"]))
Step 21: Time & Date
Example:
import datetime
now = [Link]()
print([Link]("%Y-%m-%d %H:%M:%S"))
Step 22: Virtual Environments
Command:
python -m venv myenv
This creates an isolated project environment.
Step 23: Pip & Libraries
Command:
pip install requests
Example:
import requests
response = [Link]("[Link]
print([Link]())
Step 24: Mini Project – Guessing Game
Example:
import random
secret = [Link](1, 20)
guess = 0
while guess != secret:
guess = int(input("Guess a number (1–20): "))
if guess < secret:
print("Too low!")
elif guess > secret:
print("Too high!")
else:
print("You got it!")