- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10784 Articles for Python
471 Views
In this article, we will learn a Python program to concatenate every element across lists. Methods Used The following are the various methods to accomplish this task − Using the List Comprehension and String Concatenation Using itertools.product() Function Example Assume we have taken two input lists. We will now concatenate every element across the given two lists Input inputList1 = ["hello", "tutorialspoint", "python"] inputList2 = ["coding", "articles"] Output Resultant paired combinations list: ['hello coding', 'hello articles', 'tutorialspoint coding', 'tutorialspoint articles', 'python coding', 'python articles'] Method 1: Using the List Comprehension and String Concatenation List Comprehension When ... Read More
241 Views
In this article, we will learn how to capitalize repeated characters in a string in python. Methods Used The following are the various methods to accomplish this task - Using Dictionary Hashing Using count() Function Using replace() and len() functions Using Counter() function Example Assume we have taken an input string containing some random text. We will now convert the repeated characters in an input string into uppercase using the above methods. Input inputString = 'hello tutorialspoint' Output heLLO TuTOrIaLspOInT In the above input string, the characters l, o, t, i are repeated. Hence they are ... Read More
441 Views
In this article, we will learn how to get alternate list elements as key-value pairs in python. Assume we have taken an input list containing integers. We will now Methods Used The following are the various methods used to accomplish this task − Using for loop Using dictionary comprehension and list slicing Example Assume we have taken an input list. We will now print alternate list elements as key-value pairs. Input inputList = [20, 13, 5, 2, 6, 8, 18, 3] Output Dictionary with alternate list elements as key-value pairs: {13: 2, 2: 8, 8: 3, 20: ... Read More
681 Views
In this article, we will learn how to find common keys in a list and dictionary in python. Methods Used The following are the various methods to accomplish this task − Using the ‘in’ operator and List Comprehension Using set(), intersection() functions Using keys() function & in operator Using the Counter() function Example Assume we have taken an input dictionary and list. We will find the common elements in the input list and keys of a dictionary using the above methods. Input inputDict = {"hello": 2, "all": 4, "welcome": 6, "to": 8, "tutorialspoint": 10} inputList = ["hello", "tutorialspoint", ... Read More
125 Views
In this article, we will learn how to find the difference of the sum of list elements that are missing from Matrix and vice versa. Methods Used The following are the various methods to accomplish this task − Using for loop & from_iterable() function Using sum() & from_iterable() functions Using the Counter() function Example Assume we have taken an input matrix and a target list. We will now find the difference of the sum of list elements that are missing from Matrix and vice versa. Input inputMatrix = [[6, 3, 2], [5, 4, 1], [10, 8, 1], [15, ... Read More
4K+ Views
In this article, we will learn Case insensitive string replacement in python. Methods Used The following are the various methods to accomplish this task − Using re.IGNORECASE, re.escape(), re.sub() Using re.sub(), lambda, re.escape() functions Using split(), lower() & replace() functions Using split(), list() and join() functions Method 1: Using re.IGNORECASE, re.escape(), re.sub() re.compile() function A regular expression pattern can be combined with pattern objects, which can then be used for pattern matching. This function also allows searching for a pattern again without rewriting it. Syntax re.compile(pattern, repl, string) re.sub() function The string with replaced ... Read More
950 Views
In this article, we will learn a python program to interchange elements of the first and last rows in a matrix. Methos Used Using Temporary Variable(Using Nested Loops) Using Swapping(“, ”) Operator(Without Using Any Loops) Using pop(), insert() & append() functions Method 1: Using Temporary Variable(Using Nested Loops) Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a function swapFirstandLastRow() to swap the first and last rows of an input matrix by accepting the input matrix, rows, and columns as arguments. Traverse through the matrix rows and columns and Swap ... Read More
479 Views
In this article, we will learn a python program to interchange the diagonals of the matrix. Assume we have taken an NxN input matrix. We will now interchange the diagonals of an input matrix using the below methods. Methos Used The following are the various methods to accomplish this task − Using the Nested For Loops with Temporary Variable Using ‘, ’ Swapping Operator Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store the input number of rows of a matrix Create a function printGivenMatrix() that ... Read More
8K+ Views
In this article, we will learn how to remove the last element from the set in Python. Methods Used The following are the various methods to accomplish this task − Using the discard() function Using the remove() function Using the pop() function Using the list slicing Method 1: Using the discard() function The discard() function removes the element from the set, bypassing the element as an argument to it. Algorithm (Steps) Following are the Algorithms/steps to be followed to perform the desired task. − Create a variable to store the input set containing integers. Use the discard() ... Read More
1K+ Views
In this article, we will learn how to perform Accurate Decimal Calculations in Python. Methods Used Using the Decimal() function of the decimal Module Using the fsum() function of the math module The inability of floating-point numbers to accurately represent all base-10 numbers is a well-known drawback. Furthermore, even straightforward mathematical computations have few errors. For instance − Example The following program shows the inability of floating-point integers to express all base-10 numbers accurately − x = 4.2 y = 3.1 # printing the sum of both the variables print("x + y =", x + ... Read More