Skip to main content

ads1

Class 11th Chapter 6 :- List Manipulation

 Class 11th Chapter 6 :- List Manipulation



1. How are lists different from the strings when both are sequences ? SOLUTION, The lists and strings are different in following ways: 

(i) The lists are mutable sequences while strings are immutable.

(ii) In consecutive locations, strings store the individual characters while list stores the references of its elements.

(ii) Strings store single type of elements - all characters while lists can store elements belonging to different types. Assume the following list definition in Python.

2. What are nested lists?

SOLUTION. When a list is contained in another list as a member-element, it is called nested list, eg.

3. What is the difference between append() and extend() functions? SOLUTION. The append() can append only a single element to a list while extend() can append a list of elements to a list, eg

>>> val = [17, 24, 15, 30]

>>> val.extend([34, 27]) >>> val.append(44)

>>> val [17, 24, 15, 38, 34, 27, 44]

4. What is the difference between sort) and sorted() functions ? SOLUTION Both sort() and sorted() sort the list elements, but, the primary difference between the list sort() function and the sorted() function is that the sort() function will modify the list it is working on.

The sorted() function will create a new list containing a sorted version of the list it is given. Th sorted() function will not modify the list passed as a parameter. The sortf) works on a list whereas the sorted() can work on different types of iterable sequetion Also, the sorted() function always returns a list whereas the sort() function modifies the list in-place and has no return value.

5. Define list ?

Solution :- A list in Python is used to store the sequence of various types of data. Python lists are mutable type its mean we can modify its element after it created.
A list can be defined as a collection of values or items of different types. The items in the list are separated with the comma (,) and enclosed with the square brackets [].

6. What are the Characteristics of Lists
Solution :- The list has the following characteristics:

The lists are ordered.
The element of the list can access by index.
The lists are the mutable type.
The lists are mutable types.
A list can store the number of various elements.

7. Define Indexing and splitting ?
Solution :- The indexing is processed in the same way as it happens with the strings. The elements of the list can be accessed by using the slice operator [].

The index starts from 0 and goes to length - 1. The first element of the list is stored at the 0th index, the second element of the list is stored at the 1st index, and so on.

We can get the sub-list of the list using the following syntax.
list_varible(start:stop:step)  
The start denotes the starting index position of the list.
The stop denotes the last index position of the list.
The step is used to skip the nth element within a start:stop

8. Write a note on Updating List values?
Solution :- 
Lists are the most versatile data structures in Python since they are mutable, and their values can be updated by using the slice and assignment operator. Python also provides append() and insert() methods, which can be used to add values to the list.

list = [1, 2, 3, 4, 5, 6]     
print(list)     
# It will assign value to the value to the second index   
list[2] = 10   
print(list)    
# Adding multiple-element   
list[1:3] = [89, 78]     
print(list)   
# It will add value at the end of the list  
list[-1] = 25  
print(list)  

The list elements can also be deleted by using the del keyword. Python also provides us the remove() method if we do not know which element is to be deleted from the list.

example :- 
list = [1, 2, 3, 4, 5, 6]     
print(list)     
# It will assign value to the value to second index   
list[2] = 10   
print(list)    
# Adding multiple element   
list[1:3] = [89, 78]     
print(list)   
# It will add value at the end of the list  
list[-1] = 25  
print(list)  





ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-