How to Add Numbers to Lists in Python+R

How to Add Numbers to Lists in Python+R

This newsletter is intended to be short and this week it is very short because I only have 5 minutes before I need to make coffee and go to work!

Transitioning from R to Python list comprehensions can be a little confusing but they are a powerful way to write for loops. As an R user writing a for loop for a simple vector addition may not make sense but in Python land for loops abound.

In the example code below I want to add the same number to each member of a list. In R this is simple and intuitive. In Python this type of thing will result in an error because Python thinks you want to concatenate two things of different type.

That's it for today. Happy Twosday!

No alt text provided for this image


21, 01, 2021

Brett Harries

Experienced Mining and Metals Professional

3y

As always Matt Rosinski, an endless source of useful info for our team and others!

mohammad Abdollahzadeh

computational Condensed Matter Physics at KHU

3y

😀 🤞

To view or add a comment, sign in

More articles by Matt Rosinski

Insights from the community

Others also viewed

Explore topics