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
Python Articles - Page 890 of 1048
540 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a hexadecimal string, we need to convert it into its decimal equivalent.We have two approaches to solve the problem−Brute-force ApproachUsing Built-in moduleBrute-Force MethodHere we take the help of explicit type casting function i.e. integer. This function takes two arguments i.e. hex equivalent and base i.e. (16). This function is used to convert a hexadecimal string to its equivalent decimal in an integer type, which can be further typecasted back to string format.Example Live Demo#input string string = 'F' # converting hexadecimal string ... Read More
245 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list iterable, we need to convert it into a string type iterable.There are four approaches to solve the given problem. Let’s see them one by one−Brute-force ApproachExample Live Demodef listToString(s): # initialize an empty string str_ = "" # traverse in the string for ele in s: str_ += ele # return string return str_ # main s = ['Tutorials', 'Point'] print(listToString(s))OutputTutorialsPointUsing Built-In join() methodExampledef listToString(s): # initialize an empty string ... Read More
473 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given string (containing both vowel and consonant letters), remove all consonants, then check if the resulting string is a palindrome or not.Here we first remove all the consonants present in the string. A loop to calculate the divisors by computed by dividing each value from 1 to the minimum computedEach time the condition is evaluated to be true counter is incremented by one.Remove all the consonants in the string. Now we check whether the vowel string is a palindrome or not i.e. ... Read More
507 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a number, we need to check that the number is a power of two or not.Keywords are the special words reserved by any language with specific usage and cannot be used as an identifier.To check whether the given string is a keyword we used the keyword module as discussed below.Example Live Demo# keyword module import keyword # Function def isKeyword(word) : # list of all keywords keyword_list = keyword.kwlist # check the presence if word in keyword_list : ... Read More
585 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a range, we need to find the number of odd factors in the range.ApproachAs we all know that all perfect squares have an odd number of factors in a range. So here we will compute a number of perfect squares.As m and n both are inclusive, so to avoid error in case of n being a perfect square we take n-1 in the formulae.Now let’s see the implementation below−Example Live Demo# count function def count(n, m): return int(m**0.5) - int((n-1)**0.5) # ... Read More
1K+ Views
In this article, we will learn about the solution to the problem statement given below.Problem statement− We are given a number, we need to find the nth multiple of a number k in Fibonacci number.The solution to the problem is discussed below−Example Live Demo# find function def find(k, n): f1 = 0 f2 = 1 i =2; #fibonacci recursion while i!=0: f3 = f1 + f2; f1 = f2; f2 = f3; if f2%k == 0: return n*i ... Read More
656 Views
Let’s start our article with an explanation of how to find the sum of even factors of a number but what are factors? Factors are the numbers which completely divide the given number leaving zero as remainder or we can say factors are the multiples of the number. Example 1 − If we are given a number 60 Factors of 60 (6*10=2*3*2*5) are 2, 5 and 3 But according to the question, we must find out the sum of even factors so, in the above given example, the even factor will be only 2. Also, if the given number is an ... Read More
334 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a number, we need to find all the prime factors of a given number.The efficient solution to the problem is discussed below −Example Live Demo# Python program to print prime factors import math # prime def primeFactors(n): # no of even divisibility while n % 2 == 0: print (2), n = n / 2 # n reduces to become odd for i in range(3, int(math.sqrt(n))+1, 2): # while ... Read More
526 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given two integers, we need to display the common divisors of two numbersHere we are computing the minimum of the two numbers we take as input. A loop to calculate the divisors by computed by dividing each value from 1 to the minimum computedEach time the condition is evaluated to be true counter is incremented by one.Now let’s observe the concept in the implementation below−Example Live Demoa = 5 b = 45 count = 0 for i in range(1, min(a, b)+1): ... Read More
2K+ Views
The Boolean values like True & false and 1&0 can be used as indexes in panda dataframe. They can help us filter out the required records. In the below exampels we will see different methods that can be used to carry out the Boolean indexing operations.Creating Boolean IndexLet’s consider a data frame desciribing the data from a game. The various points scored on different days are mentioned in a dictionary. Then we can create an index on the dataframe using True and False as the indexing values. Then we can print the final dataframe.Example Live Demoimport pandas as pd # dictionary ... Read More