- 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
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
231 Views
In analyzing data or processing data using python, we come across situations where the given list has to be remodeled or reshaped to get lists with different columns. We can achieve that with multiple approaches as discussed below.Using SlicingWe can slice the list at certain elements to create the columnar structure. Here we convert the given list into a new list where the elements are split form the middle. We sue two for loops. The outer one splits the elements from the zeroth element to the second element and the inner one from the second element to the last.Example Live Demox ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
3K+ Views
Python provides lot of flexibility to handle different types of data structures. There may be a need when you have to convert one Data Structure to another for a better use or better analysis of the data. In this article we will see how to convert a Python set to a Python dictionary.Using zip and dictThe dict() can be used to take input parameters and convert them to a dictionary. We also use the zip function to group the keys and values together which finally become the key value pair in the dictionary.Example Live Demolist_keys = {1, 2, 3, 4} list_values ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
13K+ Views
Printing double quotes is tricky, as it itself is required as part of syntax to print the strings by surrounding them. In this article we will see how these double quotes can be printed using print statement.The below scenarios will not print the double quote. The first two lines of code will give no output while the last one will through error.Example Live Demoprint(" ") print(" " " ") print(""aString"")OutputRunning the above code gives us the following result −;print(""aString"") ^ SyntaxError: invalid syntaxBut if we surround the strings with proper quotes as shown below, then the quotes can themselves get printed. ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
716 Views
A bigram is formed by creating a pair of words from every two consecutive words from a given sentence. In python, this technique is heavily used in text analytics. Below we see two approaches on how to achieve this.Using enumerate and splitUsing these two methods we first split the sentence into multiple words and then use the enumerate function to create a pair of words from consecutive words.Example Live Demolist = ['Stop. look left right. go'] print ("The given list is : " + str(list)) # Using enumerate() and split() for Bigram formation output = [(k, m.split()[n + 1]) for m ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
107 Views
If we print a given list of strings as it is, we have to use quotes and fill in a pair of matching quotes appropriately. We can avoid using quotes in the print statements by following two approaches.Using join()The join method helps us in printing the output of list elements by using any separator we choose. In the below example we choose ** as separator.Example Live Demolist = ['Mon', 'Tue', 'Wed'] # The given list print("The given list is : " + str(list)) print("The formatted output is : ") print(' ** '.join(list))OutputRunning the above code gives us the following result −The ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
2K+ Views
Instead of hard coding the path to a file to be used by a python program, we can allow the user to browse the os folder structure using a GUI and let the user select the file. This is achieved using the tkinter module in which we define a canvas and put a button on it to browse the files.In the below program, we define a file opener function. We only use this function to open a text file as python can read the content of a text file and print it out in a much readable manner. We can ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
132 Views
The Python dictionary has key and value pairs. In some situation we will need the items of the dictionary to be sorted according to the keys. In this article we'll see the different ways to get a sorted output from the items in the dictionary.Using Operator ModuleThe Operator module has itemgetter function which can take 0 as the index of input parameter for the keys of the dictionary. We apply the sorted function on top of itemgetter and get the sorted output.Example Live Demodict = {12 : 'Mon', 21 : 'Tue', 17: 'Wed'} import operator print("Given dictionary", str(dict)) print ("sorted order ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
826 Views
Tkinter is the GUI building library of python. In this article we will see how we can create a collapsible pane. They are usefult when we have some large amount of data to be displayed over a GUI canvas but we do not want to be displayed always. It is made collapsible so that it can be displayed as and when needed.The below program creates the collapsible pane where we see the result both after expanding and contracting the arrow. The code comments indicate the approach we take at each step.Examplefrom tkinter import * import tkinter as tk from tkinter ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
914 Views
Many times we use a method called data smoothing to make the data proper and qualitative for statistical analysis. During the smoking process we define a range also called bin and any data value within the range is made to fit into the bin. This is called the binning method. Below is an example of binning. Then we will see how we can achieve the binning method using a Python program.Binning ExampleLet’s take a series of numbers. Find the maximum and minimum values. Decide on the number of bins we need depending on how many data points the analysis needs. ... Read More
![Pradeep Elance](https://www.tutorialspoint.com/assets/profiles/121076/profile/60_44312-1565945237.jpg)
2K+ Views
The ASCII text can be used to display many stylish texts by using the module pyfiglet. After installing this module we can use it to control the font that can be used to display the result. In the below program we see various results by choosing various font types.Example# import pyfiglet module import pyfiglet #Text in default font out = pyfiglet.figlet_format("Point") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text in slant font out = pyfiglet.figlet_format("Point", font="slant") print(out)OutputRunning the above code gives us the following result −Example# import pyfiglet module import pyfiglet #Text ... Read More