Table of Contents
ToggleHow is Python Dictionaries are different from Python Lists?
First of all, going into the subject, in Python, we have various data structures. Python Lists, Tuples, Sets, Dictionaries, Strings, etc. Every structure has its properties and applications. Now, we will concentrate mainly on Lists and Dictionaries. Want to learn more about data science? Enroll in the Data Science Training institute in Pune to do so.
Both lists and dictionaries support storing different types of data. The main difference lies in their structure.’ List’ looks like just a sequence of data in square brackets. On the other hand, A ‘Dictionary’ is a key-value pair structure. Generally, the list is created with square brackets [ ] or by using a method list(), and a Dictionary will be created with the help of flower brackets or dict() method.
Let’s explore with few examples:
list1=[” apple”,’ a’]
dict1={‘a’:” apple”,1: ’a’}
We are storing only values in the list and key-value pairs in the dictionary. Well, how to access the elements inside of them. Earn yourself a promising career in data science by enrolling in the Data Science Course in Chennai with placement offered by 360DigiTMG.
print(list[1])— ‘a’— 2nd element ( index=1 ) is ‘a’ in the list
print(dict1[1])—‘a’—2nd element in the dictionary is ‘a’.
Okay… All is well.
print(list[0])—“apple” –1st element (index=0) is “apple” in the list.
print(dist1[0])
If you guess the 1st element of the dictionary as output, then you are wrong. It will give output as KeyError: 0. Looking forward to becoming a Data Scientist? Check out the Data Science Syllabus and get certified today.
We have to access the elements of dictionaries through ‘keys’ not with indexes.
print(dist1[‘a’])—“apple”. Now it is perfect.
We know both lists and dictionaries are mutable. How to modify the elements. Also, check this Data Science Certification in Bangalore to start a career in Data Science.
The same concept is applied. If lists—change through index numbers and if dictionaries—change through key names.
list1[0]=5+3j
dict1[‘a’]=True
print(list1) — the output will be [5+3j, ’a’]
print(dict1)— the output will be {‘a’: True,1: ’a’}
Dictionaries can be used in search algorithms as hash tables.
Both Lists and Dictionaries have their methods to be applied to use them effectively.
Finally, we got an idea of how dictionaries are different from Lists.
Become a Data Scientist with 360DigiTMG Data Science course in Hyderabad. Get trained by the alumni from IIT, IIM, and ISB.
Data Science Training Institutes in Other Locations
Tirunelveli, Kothrud, Ahmedabad, Hebbal, Chengalpattu, Borivali, Udaipur, Trichur, Tiruchchirappalli, Srinagar, Ludhiana, Shimoga, Shimla, Siliguri, Rourkela, Roorkee, Pondicherry, Rajkot, Ranchi, Rohtak, Pimpri, Moradabad, Mohali, Meerut, Madurai, Kolhapur, Khammam, Jodhpur, Jamshedpur, Jammu, Jalandhar, Jabalpur, Gandhinagar, Ghaziabad, Gorakhpur, Gwalior, Ernakulam, Erode, Durgapur, Dombivli, Dehradun, Cochin, Bhubaneswar, Bhopal, Anantapur, Anand, Amritsar, Agra , Kharadi, Calicut, Yelahanka, Salem, Thane, Andhra Pradesh, Greater Warangal, Kompally, Mumbai, Anna Nagar, ECIL, Guduvanchery, Kalaburagi, Porur, Chromepet, Kochi, Kolkata, Indore, Navi Mumbai, Raipur, Coimbatore, Bhilai, Dilsukhnagar, Thoraipakkam, Uppal, Vijayawada, Vizag, Gurgaon, Bangalore, Surat, Kanpur, Chennai, Aurangabad, Hoodi,Noida, Trichy, Mangalore, Mysore, Delhi NCR, Chandigarh, Guwahati, Guntur, Varanasi, Faridabad, Thiruvananthapuram, Nashik, Patna, Lucknow, Nagpur, Vadodara, Jaipur, Hyderabad, Pune, Kalyan.
Data Analyst Courses In Other Locations
Tirunelveli, Kothrud, Ahmedabad, Chengalpattu, Borivali, Udaipur, Trichur, Tiruchchirappalli, Srinagar, Ludhiana, Shimoga, Shimla, Siliguri, Rourkela, Roorkee, Pondicherry, Rohtak, Ranchi, Rajkot, Pimpri, Moradabad, Mohali, Meerut, Madurai, Kolhapur, Khammam, Jodhpur, Jamshedpur, Jammu, Jalandhar, Jabalpur, Gwalior, Gorakhpur, Ghaziabad, Gandhinagar, Erode, Ernakulam, Durgapur, Dombivli, Dehradun, Bhubaneswar, Cochin, Bhopal, Anantapur, Anand, Amritsar, Agra, Kharadi, Calicut, Yelahanka, Salem, Thane, Andhra Pradesh, Warangal, Kompally, Mumbai, Anna Nagar, Dilsukhnagar, ECIL, Chromepet, Thoraipakkam, Uppal, Bhilai, Guduvanchery, Indore, Kalaburagi, Kochi, Navi Mumbai, Porur, Raipur, Vijayawada, Vizag, Surat, Kanpur, Aurangabad, Trichy, Mangalore, Mysore, Chandigarh, Guwahati, Guntur, Varanasi, Faridabad, Thiruvananthapuram, Nashik, Patna, Lucknow, Nagpur, Vadodara, Jaipur, Hyderabad, Pune, Kalyan, Delhi, Kolkata, Noida, Chennai, Bangalore, Gurgaon, Coimbatore.
Navigate To:
360DigiTMG – Data Science, Data Scientist Course Training in Bangalore
Address: No 23, 2nd Floor, 9th Main Rd, 22nd Cross Rd,7th Sector, HSR Layout, Bangalore, Karnataka 560102.
Phone: 1800-212-654321