- 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
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
1K+ Views
A contingency table is a table showing the distribution of one variable in rows and another variable in columns. It is used to study the correlation between the two variables. It is a multiway table which describes a dataset in which each observation belongs to one category for each of several variables. Also It is basically a tally of counts between two or more categorical variables. Contingency tables are also called crosstabs or two-way tables, used in statistics to summarize the relationship between several categorical variables.The contingency coefficient is a coefficient of association which tells whether two variables or datasets ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
1K+ Views
Lists can be added in python resulting in creation of a new list containing elements from both the lists. There are various approaches to add two lists and they are described below. But in all these cases the lists must be of same length.Using Append()Using append() we can add the elements of one list to another.Example Live DemoList1 = [7, 5.7, 21, 18, 8/3] List2 = [9, 15, 6.2, 1/3, 11] # printing original lists print ("list1 : " + str(List1)) print ("list2 : " + str(List2)) newList = [] for n in range(0, len(List1)): newList.append(List1[n] + List2[n]) print(newList) ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
170 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given pos form we need to convert it into its equivalent sop formThe conversion can be done by first counting the number of alphabets in the pos form and then calculating all the max and the minterms.Now let’s observe the concept in the implementation below−Example# Python code to convert standard POS form # to standard SOP form # to calculate number of variables def count_no_alphabets(POS): i = 0 no_var = 0 # total no. of alphabets before will be ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
360 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given an interval we need to compute all the prime numbers in a given rangeHere we will be discussing a brute-force approach to get the solution i.e. the basic definition of a prime number. Prime numbers are the number which has 1 and itself as a factor and rests all the numbers are not its factors.Each time the condition of a prime number is evaluated to be true computation is performed.Now let’s observe the concept in the implementation below−Example Live Demostart = 1 ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
475 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to swap the last element with the first element.There are 4 approaches to solve the problem as discussed below−Approach 1 − The brute-force approachExample Live Demodef swapLast(List): size = len(List) # Swap operation temp = List[0] List[0] = List[size - 1] List[size - 1] = temp return List # Driver code List = ['t', 'u', 't', 'o', 'r', 'i', 'a', 'l'] print(swapLast(List))Output['t', 'u', 't', 'o', 'r', 'i', 'a', 'l']Approach 2 − The ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
973 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to insert an element in a list without changing sorted orderThere are two approaches as discussed below−Approach 1: The brute-force methodExample Live Demodef insert(list_, n): # search for i in range(len(list_)): if list_[i] > n: index = i break # Insertion list_ = list_[:i] + [n] + list_[i:] return list_ # Driver function list_ = ['t', 'u', 't', 'o', 'r'] n = ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
642 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a set, we need to list all the subsets of size nWe have three approaches to solve the problem −Using itertools.combinations() methodExample Live Demo# itertools module import itertools def findsubsets(s, n): return list(itertools.combinations(s, n)) #main s = {1, 2, 3, 4, 5} n = 4 print(findsubsets(s, n))Output[(1, 2, 3, 4), (1, 2, 3, 5), (1, 2, 4, 5), (1, 3, 4, 5), (2, 3, 4, 5)]Using map() and combination() methodExample# itertools module from itertools import combinations def findsubsets(s, n): return ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
2K+ 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.We can solve this using two approaches as discussed below.Approach 1: Taking the log of the given number on base 2 to get the powerExample Live Demo# power of 2 def find(n): if (n == 0): return False while (n != 1): if (n % 2 != 0): return False n = ... Read More
![Naveen Singh](https://www.tutorialspoint.com/articles/images/user_icon.png)
583 Views
In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a dictionary, and we need to print the 3 highest value in a dictionary.Three approaches to the problem statement are given below:Approach 1 − Calculating sum from the dictionary iterableExample Live Demo# sum function def Sum(myDict): sum_ = 0 for i in myDict: sum_ = sum_ + myDict[i] return sum_ # Driver Function dict = {'T': 1, 'U':2, 'T':3, 'O':4, 'R':5} print("Sum of dictionary values :", Sum(dict))OutputSum of dictionary values : 14Approach 2 − Calculating the ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
2K+ Views
Python gives us a generic scheduler to run tasks at specific times. We will use a module called schedule. In this module we use the every function to get the desired schedules. Below is the features available with the every function..SynatxSchedule.every(n).[timeframe] Here n is the time interval. Timeframe can be – seconds, hours, days or even name of the Weekdays like – Sunday , Monday etc.ExampleIn the below example we will see fetch the price of bitcon in every few seconds by using the schedule module. We also use the api provided by coindesk. For that purpose we will use ... Read More