
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
Found 10476 Articles for Python

217 Views
In this article, we will learn about a program in which we can remove an all characters other than alphabets using the concept of list comprehension and ord() function in Python 3.x. Or earlier.Algorithm1.We Traverse the given string to check the charater. 2.Selection of characters is done which lie in the range of either [a-z] or [A-Z]. 3.Using the join function we print all the characters which pass the test together.Exampledef remchar(input): # checking uppercase and lowercase characters final = [ch for ch in input if (ord(ch) in range(ord('a'), ord('z')+1, 1)) or (ord(ch) in range(ord('A'), ord('Z')+1, 1))] return ... Read More

363 Views
As python allows duplicate elements in a list we can have one element present multiple Times. The frequency of elements in a list indicates how many times an element occurs in a list. In this article we use the Counter function of the collections module to find out the frequency of each item in a list.SyntaxSyntax: Counter(list) Where list is an iterable in pythonExampleThe below code uses the Counter() to keep track of frequency and items() to iterate over each item in the result of counter function for printing in a formatted manner.from collections import Counter list = ['Mon', 'Tue', ... Read More

631 Views
In a list in Python we may have duplicate elements. When we count the length of the list we get the total length including the duplicate elements. But in this article we will see how to get the total count of the distinct elements or unique elements in a list.ExampleIn the below example we use the counter() from the collections module. In this module a Counter is a dict subclass for counting hashable objects. Counter is an unordered collection where elements are stored as dictionary keys and their counts are stored as dictionary values. So from the original list we ... Read More

3K+ Views
In this article, we will learn about lambda expressions and filter() functions in Python 3.x. Or earlier. These functions are present in the built-in Python standard library.What are lambda expressions?An inline function may be defined by the help of lambda expressions. A lambda expression consists of the lambda keyword followed by a comma seperated list of arguments and the expression to be evaluated using the list of arguments in the following format:Syntax Lambda arguments: expressionReturn value: The value computed by substituting arguments in the expressions.Lambda expressions are often abbreviated by the name of anonymous functions as they are not given any ... Read More

2K+ Views
In this article, we will learn about iterating/ traversing over characters of a string in Python 3.x. Or earlier.The string is a collection of characters which may contain spaces, alphabets or integers. They can be accessed using indexes or via references . Some commonly implemented methods are shown below.Method 1 − The direct itertor without indexingExamplestring_inp = "tutorialspoint" # Iterate over the string for value in string_inp: print(value, end='')Method 2 − The most common way using index based accessExamplestring_inp = "tutorialspoint" # Iterate over the string for value in range(0, len(string_inp)): print(string_inp[value], end='')Method 3 − The ... Read More

173 Views
This function is helpful in converting the letters of a word into lowercase. When applied to two strings it can match their values irrespective of the type up of the case of the letters.Applying casefold()The below example we apply the casefold() function to a string and the result comes out in all lower case letters.Examplestring = "BestTutorials" # print lowercase string print(" lowercase string: ", string.casefold())OutputRunning the above code gives us the following result −Lowercase String: besttutorialsComparing using casefold()We can compare two strings which have same letters but in different cases after applying the casefold() function. The result of the ... Read More

247 Views
The callable() function in python is part of its standard library which returns true if the object is callable and returns false if it is not.The object itself should have a call method to be callable. For example if we just declare a variable with value, it is not callable, but if we declare a function then it becomes callable.Callable ObjectBelow we declare a function which is callable. That can be verified by actually making a call to the function, as well as checking through the callable function.Exampledef func_callable(): x = 3 y = 5 z = ... Read More

443 Views
In this article, we will learn about iterating/traversing over a list in Python 3.x. Or earlier.A list is an ordered sequence of elements. It is a non-scalar data structure and mutable in nature. A list can contain distinct data types in contrast to arrays storing elements belonging to the same data types.Method 1 − Using iterable without indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's', 'p', 'o', 'i', 'n', 't'] # Iterate over the list for value in list_inp: print(value, end='')Method 2 − Using general way via indexExamplelist_inp = ['t', 'u', 't', 'o', 'r', 'i', ... Read More

1K+ Views
The bin() function converts a decimal to binary. You can use a positive or negative integer as the parameter to be converted.SyntaxBelow is the syntax of the function.bin(n) Parameters : an integer to convert Return Value : A binary string of an integer or int object. Exceptions : Raises TypeError when a float value is sent as argument.In the below example we convert a positive and a negative integer to binary. The results come out with a prefix of 0b to indicate that the number is a binary representation.Examplen = input("Enter an integer :") dec_number = int(n) bin_number = bin(dec_number) ... Read More

7K+ Views
Sometimes we need to go through the elements of a list in backward order. To achieve this we need to read the last element first and then the last but one and so on till the element at index 0. Various python programming features can be used to achieve this.Using range(N, -1, -1)We are using the range function but starting with the position -1. This value helps us read the list from the last index value also we iterate through steps of -1. In the below example we start at a position which is measured by taking the length of ... Read More