StudenteCare mission is to give people the power to build educational community and bring the Educators, Students, Parents, Consultant, University, Colleges, Schools and Coachings closer together
Ncert Solution | Ncert Solution for class 11th | Ncert Solutions for class 11 Computer Science Python | NCERT COMPUTER SCIENCE PYTHON CHAPTER 13 LISTS, DICTIONARIES AND TUPLES
by   Pooja Singla
Files Overall Price:    0.00
Videos Overall Price:    0.00
Total Overall Price:    0
Sold By:    Pooja Singla


Description Above File

NCERT Solutions for Class 11 Computer Science (Python) Chapter 13 Lists, Dictionaries and Tuples

Ncert solutions for class 11 Computer Science Python Chapter 13 Lists, Dictionaries and Tuples are prepared by CBSE student eCARE expert to score good marks in class 11. Classes 11 Computer Science Python Chapter 13 Lists, Dictionaries and Tuples contain many topics which are very important to score good in class 11. There are some important topic mentioned below:

The most basic data structure in Python is the sequence. Each element of a sequence is assigned a number – its position or index. The first index is zero, the second index is one, and so forth. Python has six built -in types of sequences, but the most common ones are lists and tuples.
There are certain things you can do with all sequence types. These operations include indexing, slicing, adding, multiplying, and checking for membership. In addition, Python has built-in functions for finding the length of a sequence and for finding its largest and smallest elements.

The 3 main characteristics are :

  1. Dictionaries are Unordered : The dictionary elements (key-value pairs) are not in ordered form.
  2. Dictionary Keys are Case Sensitive : The same key name but with different case are treated as different keys in Python dictionaries.
  3. No duplicate key is allowed : When duplicate keys encountered during assignment, the last assignment wins.
  4. Keys must be immutable : We can use strings, numbers or tuples as dictionary keys but something like [‘key’] is not allowed.



Description Below File

Some questions are asked by class 11 students related to Computer Science (Python)

Question 1:
Define list in Python.
Answer:
The list is a most versatile datatype available in Python which can be written as a list of comma- separated values (items) between square brackets. Good thing about a list is that items in a list need not all have the same type. Creating a list is as simple as putting different comma-separated values between square brackets.
For example :
list1 = [‘physics’, ‘chemistry’, 1997,2000];
list2 = [1,2, 3,4, 5];
list3 = ’[‘a”, “b”, “c”, “d”];

Question 2:
Give an example to access values in lists.
Answer:
To access value in lists, use the square brackets for slicking along with the index or indices to obtain value available at that index. Following is a simple example :

# !/user/bin/python
list1 = [‘physics’, ‘chemistry’, 1997, 2000];
list2 = [1, 2, 3, 4, 5, 6, 7];
print “list1 [0]:”,
list1 [0] print “list2[1 :5]:”, list2[1:5]

When the above code is executed, it produces the following result:

list1 [0]: physics
list2[1:5] : [2, 3, 4, 5]

Question 3:
Give an example to update single or multiple elements of lists
Answer:
You can update single or multiple elements of lists by giving the slice on the left-hand side of the assignment operator, and you can add elements in a list with the append( ) method. Following is a simple example:

# !/user/bin/python
listl = [‘physics’, ‘chemistry’, 1997, 2000];
print “Value available at index 2 :”
print list[2];
list[2] = 2001;
print “New value available at index 2 :”
print list [2];
Note: append)) method is discussed in subsequent section.

When the above code is executed, it produces the following result:

Value available at index 2 :
1997
New value available at index 2 :
2001

Question 4:
Give an example to remove list element.
Answer:
To remove a list element, you can use either I the del statement if you know exactly which ‘ element(s) you are deleting or the remove I ( ) method if you do not know. Following is a simple example:

# !/user/bin/python
list1 = [‘physics’, ‘chemistry’, 1997, 2000];
print list1;
del list1 [2];
print “After deleting value at index 2 :”
print list1;

When the above code is executed, it produces the following result:

[‘physics’, ‘chemistry’, 1997, 2000];
After deleting value at index 2;
[‘physics’, ‘chemistry’, 2000]

Question 5:
Describe list() with its syntax.
Answer:
The method list() takes sequence types and converts them to lists. It is used to convert a given tuple into list.
Syntax
Following is the syntax for list() method :
list (seq)

Question 6:
Write the output of the given Python code :

#!/user/bin/python
list1, list2 = [123, ‘xyz’], [456, ‘abc’]
print cmpt(list1, list2);
print cmp(list2, list1);
list3 = list2 + [786];
print cmp(list2, list3)

Answer:

This will produce the following result:
-1
1
-1

Question 7:
Write the output of the given Python code :

#!/user/bin/python
aList = [123, ‘xyz’, ‘zara’, ‘abc’, 123];
bList = [2009, ‘manni’];
aList.extend (bList)
print “Extended List :”, aList;

Answer:

This will produce the following result:
Extended List : [123, ‘xyz’, ‘zara’, ‘abc’, 123, 2009, ‘manni’]

Question 8:
Write the output of the given python code :

# ! ‘user/bin’pvthon
aList1 = [123, ‘xvz’, zara’, abc’];
print “Index for xyz : ” aList. index) ‘xyz’);
print “Index for zara :”, aList. index(‘zara’);

Answer:

This will produce the following result:
Index for xyz : 1 Index for xxx : 2

Question 9:
Write the output of the given python code :
# !/user/bin/python
aList = [123, ‘xyz’, ‘zara’, ‘abc’];
aList.insert (3,2009) print “Final List:”, aList
Answer:
Output:
Final List: [123, ‘xyz’, ‘zara’, 2009, ‘abc’]

Question 10:
Write the output of the given python code :

#!/user/bin/python
aList1 = [123, ‘xyz’, ‘zara’, ‘abc’];
aList.insert (3,2009) print “Final Lista List

Answer:

Output:
Final List: [123, ‘xyz’, ’zara1, 2009,’abc1’]

Question 11:
Write the output of the given python code :

# !/user/bin/python
aList1 = [123, ‘xyz’, ‘zara’, ‘abc’];
print “A List:”, aList.pop()
print “B List:”, aList.pop(2)

Answer:

Output:
A List: abc B List: zara

Question 12:
Write the output of the following code [CBSE Text Book]

A = [2, 4, 6, 8,10]
L = len (A)
S = o
for I in range (1, L, 2):
S + = A[I]
print “Sum=”, S

Answer:

Sum = 12
Justification:
A[1] = 4 step size = 2
A[3] = 8
S = 4 + 8 = 12

Question 13:
How are lists different from strings when both are sequences ?
Answer:
The lists and strings are different in following ways :

(a) The lists are mutable sequences while strings are immutable.
(b) Strings store single type of elements, all characters while lists can store elements belonging to different types.
(c) In consecutive locations, strings store the individual characters while list stores the references of its elements.

Question 14:
Write a program to calculate and display the sum of all the odd numbers in the list.
Answer:

pos = 0
sum = 0
while pos < len (L):
if L[pos] %2 = = 1 :
sum = sum + L [pos]
pos = pos + 1
print sum

Question 15:
Define a function overlapping ( ) that takes two lists and returns True if they have at least one member in common, False otherwise.
Answer:

def overlapping (a, b):
11 = len (a)
12 = len (b)
for i in range (11):
for j in range (12):
if a[i] == b[j] :
return True
else
return False