Difference between a list and a dictionary in Python

    dictionary (dict)
    • A dict is a collection of unordered key : value pairs
    • dictionaries are accessed via keys
    • count( ) does not work with dictionary
    • dictionary cannot be reversed
    • dictionary does not support indexing or slicing
    • A dictionary uses curly braces ({ })
    list
    • A list is an ordered sequence of objects
    • lists are accessed via indices
    • count( ) gives the count of an element in the list
    • list can be reversed
    • lists can use indexing or slicing
    • A list uses square brackets ([ ])
    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
    Count() methods returns the number of times an element appeared in list. Count() method does not exists in dictionation
    Sort() method sorts the elements in ascending or descending order. Sort() method sorts the keys in the dictionary by default
    We can access the elements using the index value. We can access the elements using the keys
    A list is an ordered sequence of objects, whereas dictionaries are unordered sets. However, the main difference is that items in dictionaries are accessed via keys and not via their position
    Reverse() method reverse the list elements. Dictionary items cannot be reversed as they are the key-value pairs


difference_between_a_dictionary_and_a_list
gk