Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 489 of 3366
304 Views
In this article, we will learn how to extract strings with a digit in python. Methods Used The following are the various methods to accomplish this task − Using list comprehension, any() and isdigit() functions Using any(), filter() and lambda functions Without using any built-in functions Using ord() function Example Assume we have taken an input list containing strings. We will now extract strings containing a digit in an input list using the above methods. Input inputList = ['hello562', 'tutorialspoint', 'python20', 'codes', '100'] Output List of Strings containing any digits: ['hello562', 'python20', '100'] In the above ... Read More
8K+ Views
In this article, we will a python program to count the number of spaces in a string. Methods Used The following are the various methods to accomplish this task − Using for loop (with indexing) Using count() function Using isspace() function Using Counter() function Using countOf() function of the operator module Assume we have taken an input string. we will now count the number of spaces in an input string above methods. Method 1: Using for loop (with indexing) Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired task –. Create a function ... Read More
2K+ Views
In this article, we will learn how to count Words with a specific letter in a string in python. Methods Used The following are the various methods to accomplish this task − Using list comprehension, len() & split() functions Using split() & find() functions Using split(), replace() & len() functions Using Counter() function Example Assume we have taken an input string and some random character. We will now count the words that contain the given input character in an input string. Input inputString = 'hello tutorialspoint python codes' inputChar = "p" Output Count of words containing the ... Read More
656 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
395 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
681 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
900 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
214 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
5K+ 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
1K+ 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