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:
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
List Data Type
Imagine you're organising a small party. You have a guest list — a single piece of paper where you write down names, one after another, in a specific order.
Most relevant Q&A
- #list1 is the list of six even numbers >>> list1 = [2,4,6,8,10,12] >>> print(list1) [2, 4, 6, 8, 10, 12] #list2 is the list of vowels >>> li…Preview
- What will be the output of the following statements? a) list1 = [12,32,65,26,80,10] list1.sort() print(list1) b) list1 = [12,32,65,26,80,10]…Free
- Consider the following list myList. What will be the elements of myList after each of the following operations? myList = [10,20,30,40] a) my…Free
- What will be the output of the following code segment? a) myList = [1,2,3,4,5,6,7,8,9,10] del myList[3:] print(myList) b) myList = [1,2,3,4,…Preview
- The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list: stRecord = ['Raman'…Preview
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
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.
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.
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.
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.
Concatenation
Concatenation is the merging of two or more values into one — the way two strings can be joined end to end.
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 .
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…
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…
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.
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…
List Manipulation
3 QEverything learnt so far — creating lists, indexing them, and the methods append(), insert(), extend(), pop(), remove(), sort() — comes together in complete programs.
+−Programs1 question
+−Programs1 question
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?".
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.
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.
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.
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.
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.
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,…
Manipulating Dictionaries
3 QCreating 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.
+−Programs1 question
+−Programs1 question
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
+−Show 8 questionsHide questions8 questions
- Q1What will be the output of the following statements? a) list1 = [12,32,65,26,80,10] list1.sort() print(list1) b) list1 = [12,32,65,26,80,10]…Free
- Q2Consider the following list myList. What will be the elements of myList after each of the following operations? myList = [10,20,30,40] a) my…Free
- Q3What will be the output of the following code segment? myList = [1,2,3,4,5,6,7,8,9,10] for i in range(0,len(myList)): if i%2 == 0: print(myL…Free
- Q4What will be the output of the following code segment? a) myList = [1,2,3,4,5,6,7,8,9,10] del myList[3:] print(myList) b) myList = [1,2,3,4,…Preview
- Q5Differentiate between append() and extend() methods of list.Preview
- Q6Consider a list: list1 = [6,7,8,9] What is the difference between the following operations on list1: a) list1 * 2 b) list1 *= 2 c) list1 = l…Preview
- Q7The record of a student (Name, Roll No, Marks in five subjects and percentage of marks) is stored in the following list: stRecord = ['Raman'…Preview
- Q8Consider the following dictionary stateCapital: stateCapital = {"Assam":"Guwahati", "Bihar":"Patna","Maharashtra":"Mumbai", "Rajasthan":"Jai…Preview
More questions
14 Q+−Show 10 questionsHide questions10 questions
- Q1Write a program to find the number of times an element occurs in the list.Free
- 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
- Q3Write a program to find the largest and the second largest elements in a given list of elements.Free
- 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
- 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
- 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
- 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
- Q8Write a Python program to find the highest 2 values in a dictionary.Preview
- 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
- 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 questionHide questions1 question
+−Show 3 questionsHide questions3 questions
- Q1A bank is a financial institution which is involved in borrowing and lending of money. With advancement in technology, online banking, also…Free
- 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
- 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