Found 10784 Articles for Python

How to find the element from a Python list with a minimum value?

Pranav Indukuri
Updated on 08-Nov-2022 12:41:40

2K+ Views

List is one of the most commonly used data structures provided by python. List is a data structure in python that is mutable and has an ordered sequence of elements. Following is a list of integer values − Example Following is a list of integer values. lis= [12, 22, 32, 54, 15] print(lis) Output If you execute the above snippet, it produces the following output. [12, 22, 32, 54, 15] In this article, we will look at different ways to find the minimum of the list in Python. For the above list, the minimum element of the list ... Read More

How to find the element from a Python list with a maximum value?

Pranav Indukuri
Updated on 03-Nov-2023 03:00:37

9K+ Views

List is one of the most commonly used data structures provided by python. List is a data structure in Python that is mutable and has an ordered sequence of elements. Following is a list of integer values Example Following is a list of integer values. lis= [1, 2, 3, 4, 5] print(lis) Output If you execute the above snippet, it produces the following output. [1, 2, 3, 4, 5] In this article, we will look at different ways to find the maximum of the list in Python. For the above list, the maximum element of the list is ... Read More

What are character classes or character sets used in Python regular expression?

Rajendra Dharmkar
Updated on 18-Feb-2020 10:49:31

2K+ Views

Character classA "character class", or a "character set", is a set of characters put in square brackets. The regex engine matches only one out of several characters in the character class or character set. We place the characters we want to match between square brackets. If you want to match any vowel, we use the character set [aeiou].A character class or set matches only a single character. The order of the characters inside a character class or set does not matter. The results are identical.We use a hyphen inside a character class to specify a range of characters. [0-9] matches ... Read More

How can import python module in IDE environment available in tutorialspoint?

Malhar Lathkar
Updated on 30-Jul-2019 22:30:22

566 Views

You can import any built-in module while writing Python script using TutorialsPoint's online IDE. For example you can import time, sys, os, re modules. However, the modules that are not bundled with the distribution - the one which needs to be installed using package managers like pip or conda - can not be imported.

What are the differences between “untyped” & “dynamically typed” programming languages?

Ali
Ali
Updated on 13-Jun-2020 12:51:09

2K+ Views

Dynamically typedDynamically typed language is called so because the type is associated with run-time values. You don’t have to specify types every time. As the name suggests, variables' types are dynamic, means even after you set a variable to a type you can change it.Some dynamically typed languages include Python, Perl, Ruby, etc.UntypedUntyped languages, also known as dynamically typed languages, are programming languages that do not make you define the type of a variable.JavaScript is untyped language. This means that a JavaScript variable can hold a value of any data type. To declare variables in JavaScript, you need to use the ... Read More

How to write Python regular expression to get zero or more occurrences within the pattern?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:20:19

383 Views

*      An asterisk meta-character  in a regular expression indicates 0 or more occurrences of the pattern to its leftThe following code matches and prints the zero or more occurrences of the pattern '\w' in the string 'chihua huahua'Exampleimport re s = 'chihua huahua' result = re.findall(r'\w*', s) print resultOutputThis gives the output['chihua', '', 'huahua', '']

What Python regular expression can be used in place of string.replace?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:08:42

67 Views

The following code replaces all the characters from given string with ''Exampleimport re line = 'this is a text with in between and then there are instances ... where the number ranges from 0-99.\ and there are many other lines in the text files \ with such tags ' line = re.sub(r"", "", line) print lineOutputThis gives the outputthis is a text with in between and then there are instances ... where the number ranges from 0-99.and there are many other lines in the text files with such tags

How does B regular expression work in Python?

Rajendra Dharmkar
Updated on 16-Jun-2020 11:54:00

466 Views

The word boundary \b matches positions where one side is a word character (usually a letter, digit or underscore)\B matches all positions where \b doesn't match.The following code shows how regexpr \B worksimport re result = re.findall(r'\Bcat', 'certificate') result2 = re.findall(r'\Bcat', 'tomcat') result3 = re.findall(r'\Bcat', 'catfish') print result, result2,result3This gives the output['cat'] ['cat'] []

How you can get a true/false from a Python regular expressions?

Rajendra Dharmkar
Updated on 16-Jun-2020 11:43:03

3K+ Views

When you use match and search methods of module re, if there is a match, it has bool value of True and if there is no match, you get None that has a bool value of False.Match objects are always true, and None is returned if there is no match>>> bool(re.search("def", "abcdefgh")) True >>> bool(re.search("rest", "pqrstuv")) False

How does [d+] regular expression work in Python?

Rajendra Dharmkar
Updated on 08-Sep-2023 13:12:32

2K+ Views

Regular expressions are an essential tool for searching and manipulating strings in Python. Among the various patterns and techniques available, the [d+] expression is particularly useful for matching one or more digits in a string. In this article, we will explore the [d+] regular expression pattern, its usage, and provide five code examples with step−by−step explanations to help you understand and apply this concept in your Python projects. Before diving into the code examples, let's first understand the [d+] pattern. [d+] is a combination of two elements: [d]: This is a shorthand character class for the digits 0 to 9. ... Read More

Advertisements