Pradeep Elance

Pradeep Elance

302 Articles Published

Articles by Pradeep Elance

Page 26 of 31

Append Odd element twice in Python

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 257 Views

In this article we will see how to take a list which contains some odd numbers as its elements and then add those odd elements repeatedly into the same list. Which means if odd number is present twice in a list then after processing the odd number will be present four times in that same list.For this requirement we will have many approaches where we use the for loop and the in condition or we take help of of itertools module. We also check for the odd condition by dividing each element with two.Example Live Demofrom itertools import chain import numpy ...

Read More

Append at front and remove from rear in Python

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 283 Views

When using Python for data manipulation we frequently and remove elements from list. There are methods which can do this effectively and python provides those function as part of standard library as well as part of external library. We import the external library and use it for this addition and removal of elements. Below we will see two such approaches.Using + operatorExample Live Demovalues = ['Tue', 'wed', 'Thu', 'Fri', 'Sat', 'Sun'] print("The given list : " ,values) #here the appending value will be added in the front and popping the element from the end. result = ['Mon'] + values[:-1] print("The values ...

Read More

after method in Python Tkinter

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 3K+ Views

Tkinter is a python library to make GUIs. It has many built in methods to create and manipulate GUI windows and other widgets to show the data and GUI events. In this article we will see how the after method is used in a Tkinter GUI.Syntax.after(delay, FuncName=FuncName) This method calls the function FuncName after the given delay in milisecondDisplaying WidgetHere we make a frame to display a list of words randomly. We use the random library along with the after method to call a function displaying a given list of text in a random manner.Exampleimport random from tkinter import * ...

Read More

Adding a Chartsheet in an excel sheet using Python XlsxWriter module

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 518 Views

In addition to python’s own libraries, there are many external libraries created by individual authors which do a great job of creating additional features in python. Xlsx library is one such library which not only creates excel files containing data from python programs but also creates charts.Creating Pie ChartIn the below example we will create a pie chart using the xlsxwriter writer. Here we first define a workbook then add a worksheet to it in the next step we define the data and decide on the columns where the data will be stored in an excel file based on those ...

Read More

Add the element in a Python list with help of indexing

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 233 Views

A python list is a collection data type that is ordered and changeable. Also, it allows duplicate members. It is the most frequently used collection data type used in Python programs. We will see how we can add an element to a list using the index feature.But before adding the element in an existing link, let's access the elements in a list using the index feature.Accessing List using Indexevery element in the list is associated with an index and that is how the elements remain ordered. We can access the elements by looping through the indexes. The below program prints ...

Read More

Add similar value multiple times in a Python list

Pradeep Elance
Pradeep Elance
Updated on 02-Jan-2020 7K+ Views

There are occasions when we need to show the same number or string multiple times in a list. We may also generate these numbers or strings for the purpose of some calculations. Python provides some inbuilt functions which can help us achieve this.Using *This is the most used method. Here we use the * operator which will create a repetition of the characters which are mentioned before the operator.Example Live Demogiven_value ='Hello! ' repeated_value = 5*given_value print(repeated_value)Running the above code gives us the following result:Hello! Hello! Hello! Hello! Hello!Using repeatThe itertools module provides repeat function. This function takes the repeatable string ...

Read More

Python Program to print the diamond shape

Pradeep Elance
Pradeep Elance
Updated on 30-Dec-2019 472 Views

The looping features in python can be used to create many nicely formatted diagrams using various characters from the keyboard. One such shape is diamond shape which will involve multiple loops. This is because we have to print the character both vertically and horizontally. Also we have to take care of the shape gradually growing from top till middle and then gradually shrinking from middle till the bottom. For this reason, we will use two for loops each containing one more for loop inside it.Below is the code for creating the diamond shape.Exampledef Shape_of_Diamond(shape): a = 0 for m in ...

Read More

Find minimum of each index in list of lists in Python

Pradeep Elance
Pradeep Elance
Updated on 30-Dec-2019 2K+ Views

In some problems we need to identify the minimum of each element in a list. But in solving the matrix operations, we need to find the minimum of each column in the matrix. That needs us to find the minimum value from list of lists. Because each column of a matrix is a list of lists.Using min() and zip()In the below example we use the min() and zip(). Here the zip() function organizes the elements at the same index from multiple lists into a single list. Then we apply the min() function to the result of zip function using a ...

Read More

Nested list comprehension in python

Pradeep Elance
Pradeep Elance
Updated on 30-Dec-2019 2K+ Views

A nested list is a list within a list. Python provides features to handle nested list gracefully and apply common functions to manipulate the nested lists. In this article we will see how to use list comprehension to create and use nested lists in python.Creating a MatrixCreating a matrix involves creating series of rows and columns. We can use for loop for creating the matrix rows and columns by putting one python list with for loop inside another python list with for loop.Example Live Demomatrix = [[m for m in range(4)] for n in range(3)] print(matrix)Running the above code gives us ...

Read More

Event scheduler in Python

Pradeep Elance
Pradeep Elance
Updated on 23-Dec-2019 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
Showing 251–260 of 302 articles
« Prev 1 24 25 26 27 28 31 Next »
Advertisements