惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
爱范儿
爱范儿
宝玉的分享
宝玉的分享
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 叶小钗
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
博客园 - 司徒正美
博客园 - 【当耐特】
IT之家
IT之家

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
List in python
Sakthivel V · 2026-06-02 · via DEV Community

Sakthivel V

List

  • Lists are used to store multiple items in a single variable.
  • Lists are created using square brackets.
  • List is a built-in data structure used to store an ordered collection of items. They are dynamic, resizable and capable of storing multiple data types.

Ex:

a = [1, 2, 3]
print(a)

b = ["apple", "banana"]
print(b)

List Items - Data Types

  • List items can be of any data type.
  • A list with strings, integers and boolean values.

Ex:

list1 = ["apple", 1 , False]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]

print(list1)
print(list2)
print(list3)

List Operations:

There are several kinds of list operations,they are:

  1. Add()
  2. Delete()
  3. Reorder()

Add():

  • append() → Adds an item at the end.
  • insert() → Adds an item at a specific position.
  • extend() → Adds multiple items from another list.

Delete():

  • pop() → Removes item by index (default: last item).
  • remove() → Removes item by value.
  • clear() → Removes all items.

Reorder():

  • sort() → Sorts items in ascending order.
  • reverse() → Reverses the order of items.

Practice problems:

  1. Input: [56, 54, 100, 35, 83, 81, 100, 66, 93, 81, 79, 67, 100, 50, 74, 59, 100, 61, 37, 60]
  2. Given math scores, find how many scored centum: 100
  3. Given scores, grade each score: A > 90, B > 80, C > 60, others D
  4. Given scores, count students for each grade
input = [56, 54, 100, 35, 83, 81, 100, 66, 93, 81, 79, 67, 100, 50, 74, 59, 100, 61, 37, 60]
count = 0
for i in input:
    if i == 100:
        count = count + 1
print("Centum scored: ", count)


grade_A = 0
grade_B = 0
grade_C = 0
grade_D = 0

for i in input:
    if i > 90:
        grade_A = grade_A + 1
    elif i > 80:
        grade_B = grade_B + 1
    elif i > 60:
        grade_C = grade_C + 1
    else:
        grade_D = grade_D + 1

print("A_Grade: ", grade_A)
print("B_Grade: ", grade_B)
print("C_Grade: ", grade_C)
print("D_Grade: ", grade_D)

  1. Given numbers, reverse numbers [1, 2, 3] -> [3, 2, 1]
num = [1, 2, 3]
num.reverse()
print("Reversed numbers: ", num)

  1. Given numbers, rotate them in place N times [1, 2, 3, 4, 5] -> [4, 5, 1, 2, 3]
nums = [1, 2, 3, 4, 5]
N = 2

for i in range(N):
    last = nums.pop()
    nums.insert(0, last)   

print("Rotated list:", nums)

  1. Given numbers, double them in place [1, 2, 3, 4, 5] -> [2, 4, 6, 8, 10]
num = [1, 2, 3, 4, 5]
for i in range(len(num)):
    num[i] = num[i] * 2
print("Doubled numbers: ", num)

  1. Sort given numbers
num = [1, 2, 3, 4, 5]
num.sort()
print("Sorted numbers: ", num)

  1. Sum of given numbers
num = [1, 2, 3, 4, 5]
total = 0
for i in num:
    total = total + i
print("Sum of numbers: ", total)

  1. Find even, odd
input = [56, 54, 100, 35, 83, 81, 100]

for i in input:
    if i % 2 == 0:
        print(i, "is even")
    else:
        print(i, "is odd")

  1. Multiply by 2
num = [1, 2, 3, 4, 5]
for i in range(len(num)):
    num[i] = num[i] * 2
print("Multiplied by 2: ", num)

  1. Compare two lists for equality
list1 = [1, 2, 3]
list2 = [4, 5, 6]
if list1 == list2:
    print("Lists are equal")
else:
    print("Lists are not equal")