Skip to main content

Posts

Showing posts with the label why

Dictionary on Python Hunter by Pran Sukh

We have learned about list in previous blogs, list can contain dictionary object vice versa. Both has the ability to change their size at run time. list and dictionary can grow and shrink according to elements at run time. But what is the actual difference b/w these two? Read below.  One is that elements from list object contains elements in linear manner but the dictionary object contains elements as key and value pair.   Elements from list object are fetched with element's location but in dictionary the elements is fetched with key. Last but not the least that list is an ordered object means when the list object is printed it shows the elements as these were inserted but dictionary sort the keys and print the values.      Examples:-  1 2 3 dict_ = dict () dict_ = { "Python" : "Hunter" , "Is" : "Better" } print (dict_) There are lot of methods to manipulate the dictionary object but some of the met...

Python Hunter, Post on Python Tuple.

Tuple is like list but unlike in structure and functionality. first basic difference is can be figured out by the structure. List elements are enclosed with '[]' brackets but tuple elements are enclosed with '()' parentheses. Few properties of tuple:- 1. It is faster than list. 2. Unlike list, tuple is immutable, i.e. tuple's data cannot be changed once created, we should use tuple if we want our data to be safe from accidental change.  As you can see in title picture, you are allowed to see but cannot touch it. 3. We can use tuple as key in dictionaries   whereas this is not the case with list,  we can’t use list as key in dictionary <Link this post (dictionary) will be available on 16 March 2018>.      Examples:-  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 myTuple= tuple ( 'Python' ) # it takes only one parameter print (myTuple) #it will break down each character into separate elements, just l...