When Do You Use List Vs. Tuple Vs. Dictionary Vs. Set

When Do You Use List Vs. Tuple Vs. Dictionary Vs. Set


  • 14 Feb, 2013

    The main difference between lists and tuples are, lists are mutable whereas tuples are not. You can always convert a tuple type object to a list type object. 

    >>> p = (1,2,3,4)
    >>> type(p)
    <type 'tuple'>
    >>> q=list(p)
    >>> type(q)
    <type 'list'>
    >>>

    Dictionaries are hash table's (so to speak) in Python. Dictionary is a powerful object  in python. Whenever you need to associate a key and value pair, it is advisable to use dictionary object.

    Comments Received:
    Please give your suggestions and feedback:
  • 23 Feb, 2012

    List and Tuple are both ordered containers. If you want an ordered container of constant elements use tuple as tuples are immutable objects.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.