Python
- 12 June
7 ways to copy a dictionary in python
💡 Outline **Shallow copy** You can use copy method of Dictionary to create shallow copy of dictionary in Python. [crayon-67903443150cc874682492/] **Deep copy** You can use deepcopy() function of copy module to create deep copy of dictionary in Python. Dictionaries are a mutable structure in Python. We can alter the key-value pairs in a dictionary without […]
- 11 June
Escape quotes in Python
💡 Outline You can use \ to escape quotes in Python. If you want to delay python program by 500 ms, then you need to pass 0.5 as parameter to sleep method. [crayon-67903443164b7302321170/] Escape sequences are frequently used in programming. They are used to convey to the compiler that the escape character has some other […]
- 07 June
Number guessing game in Python
A number guessing game is a common mini-project for basic programmers who have a grasp on random number generation and conditional statements with iteration. The number guessing game is based on a concept where player has to guess a number between given range. If player guesses the expected number then player wins else player loose […]
- 31 May
Sort list alphabetically in Python
💡 Outline You can use sort() method of list to sort list alphabetically in Python [crayon-6790344316811639730995/] In this tutorial, we will discuss different ways to sort a list namely using the sort() function, sorted() function, and implementing the quick sort algorithm. Use of the sort() function to sort list alphabetically in Python. The sort() method […]
- 31 May
Perfect number program in Python
According to number theory, a limb of pure mathematics that deals with integers, a Perfect Number can be defined as a positive integer whose value is equivalent to the sum of its proper positive divisors, excluding the number itself (alternatively known as aliquot sum). An example of a perfect number is the number 6, the […]
- 31 May
Convert Hex to bytes in Python
1. Introduction to the Problem Statement In software development, converting hexadecimal (hex) strings to byte objects is a frequent requirement, especially when dealing with data formats and encoding. Hexadecimal, being a base-16 numeral system, offers a compact way to represent binary data, which is often needed in computational tasks. For instance, converting the hex string […]
- 25 May
Find common elements in two lists in python
💡 Outline You can first convert first list into set using set() and call intersection() by passing second list as parameter to find common element in two lists in Python. [crayon-6790344316ad1503853343/] In this tutorial, we will see different methods to find common elements in two lists in python. Using the intersection() Function This is the […]
- 23 May
Remove Comma from String in Python
💡 Outline You can remove comma from string in python by using string’sreplace() method. Syntax: [crayon-6790344316b8d112493940/] In this tutorial, we will take a sample string with a couple of commas in it and we will see some methods to remove comma from string in Python. Using replace() function to remove comma from string in Python […]
- 21 May
Get filename from Path in Python
There are different ways to define the path of the file. In Windows, the path separator for a file can be either a backslash or a forward slash. The ntpath module of Python will work on all platforms for all paths. The forwardslash / is used for UNIX and MacOS operating system and backslash \ […]