Posts

Showing posts with the label Dictionary

Python Tutorial 26 --- "*args and **kwargs In Python"

Python Tutorial 26 --- "*args and **kwargs In Python" DOC: We have worked with functions lately and also have made our own functions. We have seen that a function can only pass a certain number of arguments. The number of arguments has to be decided while defining the function, and it can not be changed while calling it. In simple terms, the number of arguments passed should be the same as the ones that are defined. If we dislike this restriction and do not want ourselves to be bound by certain limits, then we are lucky to have  *args  and  **kwargs  with us. Before discussing *args and **kwargs, we should have a basic knowledge about types of arguments. In Python programming, there are two types of arguments that can be passed in a function. positional arguments keyword arguments Positional arguments  are the one in which an order has to be followed while passing arguments. We have been dealing with them until now. We know how normal functions work with positio...

Python Exercise 1--- Dictionary

 Python Exercise 1--- So, in this tutorial i.e. Python exercise 1 tutorial, what we have to do is, we have to create a dictionary, similar to the real-world dictionary. There is no limit to the definition you provide to any word as this exercise is just for your practice. The details and functionalities that are essential and must be present are: User will give a word as an input. Suppose that the word is present in your dictionary along with its definition or meaning. The program will print the meaning or definition of that word. For example: The user inputs the word : “programming” The output will be:  "the process of writing computer programs" Your main focus should be towards writing a neat and efficient code, using only the knowledge from our previously done tutorials. CODE--- #Exercise 1--- dic = { "A" : "Apple" , "B" : "Ball" , "C" : "Cat" , "D" : "Dog" } print ( "The required meaning ...

Dictionary Functions in Python

 Dictionary Functions in Python #Dictionary Functions in Python #Method #Description clear() #Removes all the elements from the dictionary copy()      #Returns a copy of the dictionary fromkeys()      #Returns a dictionary with the specified keys and value get()      #Returns the value of the specified key items() #Returns a list containing a tuple for each key value pair keys()      #Returns a list containing the dictionary's keys pop()      #Removes the element with the specified key popitem()      #Removes the last inserted key-value pair setdefault()    #Returns the value of the specified key. If the key does not exist: insert the key, with the specified value update()      #Updates the dictionary with the specified key-value pairs values()      #Returns a list...

Python Tutorial 6---"Dictionary & Its Functions"

  Python Tutorial 6--- "Dictionary & Its Functions" This PROGRAM or TUTORIAL about Python's  "Dictionary & Its Functions" DOC Let's start with the basic definition of a Python Dictionary: “Python dictionary is an unordered collection of items. Each item of the dictionary has a key/value pair.” Now coming to the more formal approach: Every programming language has its own distinct features, commonly known as its key features. That said, Python’s one out of the box feature is “dictionaries”. Dictionaries may look very similar to a “List”, but dictionaries have some distinct features that do not hold true for other data types like lists, and those features are what makes it (python dictionary) special. Here are a few important features of a python dictionary: It is unordered (no sequence is required - data or entries have no order) It is mutable (values can be changed even after its formation or new data/information can be added to the already existing ...