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!
21, 01, 2021
Experienced Mining and Metals Professional
2 年As always Matt Rosinski, an endless source of useful info for our team and others!
computational Condensed Matter Physics at KHU
2 年?? ??