Skip to main content

ads1

Class 11th Chapter 7 :- Dictionaries

Chapter 7 :- Dictionaries 


1. How are dictionaries different from lists? 

SOLUTION. The dictionary is similar to lists in the sense that it is also a collection of like lists BUT it is different from lists in the sense that lists are sequential collections (ordered) s dictionaries are non-sequential collections (unordered). In lists, where there is an order associated with the data-items because they act as storage unitat other objects or variables you've created. Dictionaries are different from lists and tuples because the group of objects they hold aren't in any particular order, but rather each object has its own uniq data-items name, commonly known as a key.

2. How are objects stored in lists and dictionaries different? 

SOLUTION. The objects of values stored in a dictionary can basically be anything (even the nothing type defined as Nene), but keys can only be immutable type-objects r.g. strings, tuples, integrs, etc When are dictionaries more useful than lists? SOLUTION. Dictionaries can be much more useful than lists. For example, suppose we wanted to all our friends' cell-phone numbers. We could create a list of pairs, (name of friend, phone number but once this list becomes long enough searching this list for a specific phone number will the time-consuming, Better would be if we could index the list by our friend's name. 

3. what a dictionary does Can sequence operations such as slicing and concatenation be applied to dictionaries ? Why?

SOLUTION. No, sequence operations like slicing and concatenation cannot be applied on diction The reason being a dictionary is not a sequence. Because it is not maintained in any specific order operations that depend on a specific order cannot be used.

4. Why can't Lists be used as keys of dictionaries?

SOLUTION. Lists cannot be used as keys in a dictionary because they are mutable. And a Pyth dictionary can have only keys of immutable types. If the addition of a new keyalue pair causes the size of the dictionary to grow beyond its original size, a occurs. 

5. Define Dictionary?
Solution :- Python Dictionary is used to store the data in a key-value pair format. The dictionary is the data type in Python, which can simulate the real-life data arrangement where some specific value exists for some particular key. It is the mutable data-structure. The dictionary is defined into element Keys and values.

Keys must be a single element
Value can be any type such as list, tuple, integer, etc.
In other words, we can say that a dictionary is the collection of key-value pairs where the value can be any Python object. In contrast, the keys are the immutable Python object, i.e., Numbers, string, or tuple.

6. How we can create a dictionary?
Solution :- 
The dictionary can be created by using multiple key-value pairs enclosed with the curly brackets {}, and each key is separated from its value by the colon (:).The syntax to define the dictionary is given below.
Example :- 
Dict = {"Name": "Tom", "Age": 22}    





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 :-