• 23 December

    Python sort list of tuples

    In this tutorial, we will see about how to sort list of tuples on the basis of various criterion. Let’s understand with the help of example Let’s say you have list of tuples as below: [crayon-662a3ec56a05c900272574/] Now you want to sort list of tuples based on age and age is 1st index in tuple. You […]

  • 16 December

    Iterate through dictionary in python

    In this post, we will see how to iterate through dictionary in python. You can use for key in dict.keys(): to iterate over keys of dictionary. [crayon-662a3ec56b845251373354/] You can use for value in dict.values(): to iterate over values of dictionary. [crayon-662a3ec56b852173610095/] You can use items() method to iterate over key-value pairs of dictionary. [crayon-662a3ec56b855095901367/] Let’s […]

  • 16 December

    Python dictionary append

    In this tutorial, we will see how to append items to dictionary. There is no method called append in dictionary in python, you can actually use update method to add key value pairs to the dictionary. Simplest way to add item to dictionary [crayon-662a3ec56ba72936237515/] Output: {1: ‘one’, 2: ‘two’, 3: ‘three’} {1: ‘one’, 2: ‘two’, […]

  • 15 December

    Python float to String

    In this tutorial, we will see how to convert float to String. You can simply use str method to convert float to String. Let’s understand with the help of simple example. [crayon-662a3ec56c1f7103796408/] Output: Converted f to String: 1.23444432 Let’s say you want to format String to only two decimal places. You can use below code […]

  • 15 December

    Python String to float

    In this tutorial, we will see how to convert String to float in python. You can simply use float() function to convert String to float. Let’s understand with the help of a simple example. [crayon-662a3ec56caca838034122/] Output: Type of f: 22.4543232 What happens if String cannot be converted to float If String cannot be converted to […]

  • 15 December

    Python dict setDefault

    In this tutorial, we will see about Python dict setDefault method. Python dictionary setDefault method is used to return the value if present in dictionary else inserts the key with value in dictionary if default value is provided. Syntax [crayon-662a3ec56fdae310135624/] Return It returns the value if key exists in dictionary else it inserts key with […]

  • 15 December

    Remove Key from Dictionary Python

    In this tutorial, we will see how to remove key from the dictionary in Python. There are multiple ways to do it.Let’s explore a different way of deleting a key from the dictionary. Using pop method You can use pop method to remove key from dictionary.This is cleanest way to delete key from dictionary. [crayon-662a3ec56ff4b106000323/] […]

  • 09 December

    Python String to datetime

    In this tutorial, we will see how to convert String to datetime object. Let’s say, you got String as input and you want to convert it datetime object to extract various details from it. Using strptime Using parser Using strptime method You can simply use strptime to convert String to datetime. Let’s understand with the help of […]

  • 09 December

    Python datetime to String

    In this tutorial, we will see how to convert datetime to String object. Let’s say, you have datetime as input and you want to convert it string to display it. Using strftime Using format Using strptime method You can simply use strptime to convert datetime to String. Let’s understand with the help of example. [crayon-662a3ec570127456202964/] Output: datetime […]