Difference between dictionary and list in Python







  • What is the difference between list and dictionary in Python

    Lists ordered collection of objects. Dictionary in Python on the other hand is an unordered collection of data values, used to store data values like a map, which unlike other Data Types that hold only single value as an element, Dictionary holds key:value pair.
    Mutable objects come with one potentially prominent drawback: changes made to an object are visible from every reference to that object. All mutable objects work this way because of how Python references objects, but that behavior isn’t always the most useful. In particular, when working with objects passed in as arguments to a function, the code that called the function will often expect the object to be left unchanged. If the function needs to make modifications in the course of its work, i.e. if we want to make changes to an object without those changes showing up elsewhere, we’ll need to copy the object first. Lists, support slicing to retrieve items from the list into a new list. That behavior can be used to get all the items at once, creating a new list with those same items. Simply leave out the start and end values while slicing, and the slice will copy the list automatically:
  • python bootcamp 2021
datai analytics