Print Duplicates from a List of Integers in Python

AmitDiwan
Updated on 11-Aug-2022 11:41:43

3K+ Views

We will display duplicates from a list of integers in this article. The list is can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that the items in a list need not be of the same type Let’s say we have the following input list − [5, 10, 15, 10, 20, 25, 30, 20, 40] The output display duplicate elements − [10, 20] Print duplicates from a list of integers using for loop We will display the duplicates of a list of integer using a for loop. We ... Read More

List of Keywords in Python Programming

Anvi Jain
Updated on 11-Aug-2022 11:37:47

1K+ Views

Keywords in Python are reserved words. You cannot use them as variable name, function name, class name, etc. Following are the Keywords in Python − Keywords in Python FALSE await else import pass None break except in raise TRUE class finally is return and continue for lambda try as def from nonlocal while assert del global not with async ... Read More

What is Calendar Module in Python

AmitDiwan
Updated on 11-Aug-2022 11:35:39

3K+ Views

The Calendar module in Python is used to display calendars and provides useful Built-in functions for displaying week, week day, month, month of the year, and other operations. By default, these calendars have Monday as the first day of the week, and Sunday as the last. Display the Calendar of an Year To display the calendar of an year, use the calendar() method and set year as the parameter − Example import calendar # Set the year year = 2022 # Display the calendar print(calendar.calendar(year)) Output ... Read More

Quickly Convert Decimal to Other Bases in Python

AmitDiwan
Updated on 11-Aug-2022 11:31:07

1K+ Views

To quickly convert Decimal to other based, we will be using the Built-in functions in Python − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, thousands, and so on. Binary uses two digits, 0 and 1. Also called as base 2 number system Each position in a binary number represents a 0 power of the base (2). Last ... Read More

Remove Block Tags Inside Script Element in JavaScript

Saurabh Jaiswal
Updated on 11-Aug-2022 11:30:45

821 Views

CDATA, the short form of Character Data is a block of code that has been written to prevent parsing by the parser. Sometimes our data includes predefined characters like “ Syntax str.replace("regex", "") Here str is the string from which you want to remove the CDATA, regex is the regular expression to find the block data. Example In the below program example, we remove the CDATA blocks and tags inside a script element using the String replace() method. We pass the regex defined above as an argument to the replace() method and the second argument is an empty string. ... Read More

Matrix Manipulation in Python

AmitDiwan
Updated on 11-Aug-2022 11:24:53

16K+ Views

We can easily perform matrix manipulation in Python using the Numpy library. NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of multidimensional array objects and a collection of routines for processing of array. Using NumPy, mathematical and logical operations on arrays can be performed. Install and Import Numpy To install Numpy, use pip − pip install numpy Import Numpy − import numpy Add, Subtract, Divide and Multiply matrices We will use the following Numpy methods for matrix manipulations − numpy.add() − Add two matrices numpy.subtract() − Subtract two matrices numpy.divide() ... Read More

Binary to Decimal and Vice Versa in Python

AmitDiwan
Updated on 11-Aug-2022 11:22:14

1K+ Views

In this article, we will see how to convert Binary to Decimal and Decimal to Binary. Binary is the simplest kind of number system that uses only two digits of 0 and 1 (i.e. value of base 2). Since digital electronics have only these two states (either 0 or 1), so binary number is most preferred in modern computer engineer, networking and communication specialists, and other professionals. Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, ... Read More

Convert Time from 12-Hour to 24-Hour Format in Python

AmitDiwan
Updated on 11-Aug-2022 11:11:01

5K+ Views

In this article, we will learn how to convert time from 12 to 24 hours format. Let’s say we have the following input date in 12-hour format − 10:25:30 PM The following is the output in 24-hour format − 22:25:30 Convert current time from 12 hour to 24 hour format To convert time from 12 hour to 24 hour format, here’s the code − Example import datetime def timeconvert(str1): if str1[-2:] == "AM" and str1[:2] == "12": return "00" + str1[2:-2] elif str1[-2:] == "AM": return str1[:-2] elif str1[-2:] == "PM" and str1[:2] == "12": return str1[:-2] ... Read More

Python Helpers for Computing Deltas

AmitDiwan
Updated on 11-Aug-2022 11:02:59

261 Views

The difflib module is used in Python to compute deltas. It is used to compare files, and can produce information about file differences in various formats, including HTML and context and unified diffs. We need to first import the difflib module before using it − import difflib Class (difflib.SequenceMatcher) This class is used to compare two sequences of any type. It has different methods. Some of the methods − set_seqs(a, b) − Set the sequence files which will be compared. It computes and caches detailed information about the second file. So for matching multiple files, we should set ... Read More

Python Numeric Types

AmitDiwan
Updated on 11-Aug-2022 11:00:28

5K+ Views

The Numeric Types in Python are the integer datatypes. It includes integers, floatimg point, complex, etc. The complex includes real and imag parts. Also, includes Hexadecimal and Octal types. Python int datatype The Numeric Types include the int datatypes − a = 5 print("Integer = ", a) print("Type = ", type(a)) Output Integer = 5 Type = Python float datatype The Numeric Types include the float datatypes − Example a = 7E2 print("Float = ", a) print("Type = ", type(a)) Output Float = 700.0 Type = Python complex datatype The Numeric Types include the ... Read More

Advertisements