Python
12 June7 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-690805881a801284288442/] **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 JuneEscape 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-690805881b0a9563616388/] Escape sequences are frequently used in programming. They are used to convey to the compiler that the escape character has some other […]
07 JuneNumber 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 MaySort list alphabetically in Python
💡 Outline You can use sort() method of list to sort list alphabetically in Python [crayon-690805881c897049115670/] 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 MayPerfect 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 MayConvert 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 MayFind 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-690805881f316019863200/] 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 MayRemove Comma from String in Python
💡 Outline You can remove comma from string in python by using string’sreplace() method. Syntax: [crayon-690805881f40b501630882/] 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 MayGet 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 \ […]