Skip to content

Language

Sign in

Learn › Class 11 › Computer Science / Informatics Practices › Lists, tuples, dictionaries

Lists, tuples and dictionaries

Example 1: Count runs scored by each batter

Open one step at a time. Try the next step yourself first.

  1. Step 1. runs = {}
  2. Show step 2

    for name, r in [('Virat', 40), ('Rohit', 25), ('Virat', 12)]: runs[name] = runs.get(name, 0) + r

  3. Show step 3

    runs is now {'Virat': 52, 'Rohit': 25}.

Example 2: Slicing a list

Open one step at a time. Try the next step yourself first.

  1. Step 1. L = [10, 20, 30, 40, 50]
  2. Show step 2

    L[1:4] is [20, 30, 40].

  3. Show step 3

    L[::-1] is [50, 40, 30, 20, 10], the list reversed.

Reviewed by EduFlint team on 1 Dec 2026 · version 1

Written by us for this site. Independent; not affiliated with NCERT or CBSE.

Report a mistake

Looking for another topic?