Skip to content
← Informatics Practices

Informatics Practices · Class 11 Optional

Ch 4Working with Lists and Dictionaries — Class 11 Informatics Practices, concept-first.

A list is Python's way of keeping several values together in a single, ordered container. Formally, the list data type is an ordered sequence which is mutable and is made up of one or more elements. Two words in that definition carry all the weight:

30

Q&A

11

Concepts

Not available

Exam weightage

Start learning — read this chapter →

Key concepts

Hover a concept to preview it and jump to its most relevant Q&A.

Chapter contents

The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.

4.1

Introduction to List

A list is Python's way of keeping several values together in a single, ordered container. Formally, the list data type is an ordered sequence which is mutable and is made up of one or more elements.

4.1.1

Accessing Elements in a List

Once data sits inside a list, you need a way to reach any single element directly — without walking through the others.

4.1.2

Lists are Mutable

The definition of a list calls it an ordered sequence which is mutable — and mutability is the property this section pins down.

4.2

List Operations

A list is not just a container to store values — the list data type lets you manipulate its contents through a set of built-in operations.

4.2.1

Concatenation

Concatenation is the merging of two or more values into one — the way two strings can be joined end to end.

4.2.2

Repetition

Where concatenation joins different lists, repetition replicates one list. Python allows us to replicate the contents of a list using the repetition operator, depicted by the symbol .

4.2.3

Membership

Often the question is not where an element sits in a list but simply whether it is there at all. Python answers this with the membership operators, which test a list's contents and reply with a Boolea…

4.2.4

Slicing

Indexing pulls out one element; slicing pulls out a whole run of them. A slicing operation creates a new list by taking out elements from an existing list — you name the range of indexes you want, and…

4.3

Traversing a List

Creating a list is only half the story — most programs need to visit every element of a list one after another, whether to display them, add them up, or test each one against a condition.

4.4

List Methods and Built-in Functions

Lists come with a rich set of ready-made tools: methods that belong to the list type itself (called as list1.append(...), list1.sort(), and so on) and built-in functions that take a list as an argumen…

4.5

List Manipulation

3 Q

Everything learnt so far — creating lists, indexing them, and the methods append(), insert(), extend(), pop(), remove(), sort() — comes together in complete programs.

4.6

Introduction to Dictionaries

A list answers the question "what is the element at position 3?" — but many real situations ask a different kind of question: "what are Mohan's marks?" or "what is the capital of Kerala?".

4.6.1

Creating a Dictionary

A dictionary is written between curly braces , with the items separated by commas, and each item written as a key-value pair with a colon (:) between the key and its value.

4.6.2

Accessing Items in a Dictionary

Sequences — strings, lists and tuples — hand out their elements through indexing: you ask for position 0, 1, 2 and so on. A dictionary works on a different principle.

4.6.3

Membership Operation

Accessing a missing key with square brackets ends in a KeyError, so a program often needs to check first whether a key exists.

4.6.4

Dictionaries are Mutable

Like lists — and unlike strings and tuples — dictionaries are mutable: the contents of a dictionary can be changed after it has been created.

4.7

Traversing a Dictionary

Traversing a dictionary means visiting every item it holds — each key together with its value — one at a time, usually to display them or to process them in some way.

4.8

Dictionary Methods and Built-in Functions

Python supplies a set of ready-made functions and methods for working on dictionaries, so that everyday jobs — counting the pairs, pulling out all the keys or all the values, fetching a value safely,…

4.9

Manipulating Dictionaries

3 Q

Creating a dictionary is only the starting point; the real skill is applying the methods learnt in this chapter to inspect it, query it and change it.

Summary

- Lists are mutable sequences in Python — the elements of a list can be changed after it is created. - A list is written by placing its elements inside square brackets, separated by commas, e.g.

Exercises

More questions

14 Q
+Show 10 questions10 questions
  1. Q1Write a program to find the number of times an element occurs in the list.Free
  2. Q2Write a program to read a list of n integers (positive as well as negative). Create two new lists, one having all positive numbers and the o…Free
  3. Q3Write a program to find the largest and the second largest elements in a given list of elements.Free
  4. Q4Write a program to read a list of n integers and find their median. Note: The median value of a list of values is the middle one when they a…Preview
  5. Q5Write a program to read a list of elements. Modify this list so that it does not contain any duplicate elements i.e. all elements occurring…Preview
  6. Q6Write a program to create a list of elements. Input an element from the user that has to be inserted in the list. Also input the position at…Preview
  7. Q7Write a program to read elements of a list and do the following. a) The program should ask for the position of the element to be deleted fro…Preview
  8. Q8Write a Python program to find the highest 2 values in a dictionary.Preview
  9. Q9Write a Python program to create a dictionary from a string ‘w3resource’ such that each individual character mates a key and its index value…Preview
  10. Q10Write a program to input your friend’s, names and their phone numbers and store them in the dictionary as the key-value pair. Perform the fo…Preview
+Show 1 question1 question
  1. Q1For the SMIS System given in Chapter 3, let us do the following: Write a program to take in the roll number, name and percentage of marks fo…Preview
+Show 3 questions3 questions
  1. Q1A bank is a financial institution which is involved in borrowing and lending of money. With advancement in technology, online banking, also…Free
  2. Q2Participating in a quiz can be fun as it provides a competitive element. Some educational institutes use it as a tool to measure knowledge l…Preview
  3. Q3Our heritage monuments are our assets. They are a reflection of our rich and glorious past and an inspiration for our future. UNESCO has ide…Preview