How to append output of a for loop in a python list?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

How to append output of a for loop in a python list?

How to append output of a for loop in a python list?

This recipe helps you append output of a for loop in a python list

Recipe Objective

In python, while operating on list, we might need to store each loop output with each iteration.

So this recipe is a short example on how to append output of for loop in a python list. Let's get started.

Step 1 - Setup the Data

numbers=[10,20,30,40]

Let us create a list containing some numbers.

Step 2 - Appending list in a for loop

for i in range(5,11): numbers.append(10*i)

We use append function to append a list. Here, with each loop running, the list gets appended.

Step 3 - Printing results

print(numbers)

Simply use print function to print new appended list.

Step 4 - Let's look at our dataset now

Once we run the above code snippet, we will see:

[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

Relevant Projects

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Data Science Project-TalkingData AdTracking Fraud Detection
Machine Learning Project in R-Detect fraudulent click traffic for mobile app ads using R data science programming language.

Census Income Data Set Project - Predict Adult Census Income
Use the Adult Income dataset to predict whether income exceeds 50K yr based on census data.

Digit Recognition using CNN for MNIST Dataset in Python
In this deep learning project, you will build a convolutional neural network using MNIST dataset for handwritten digit recognition.

Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

Data Science Project in Python on BigMart Sales Prediction
The goal of this data science project is to build a predictive model and find out the sales of each product at a given Big Mart store.

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.

Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.