Answers for "how to add items to a list with a loop python"

2

python assign list item in for loop

year = 2021
month_list = [1, 2, 3, 4, 5]
day = 1
date_list = []

for month in month_list:
    date_list.append( datetime(year, month, day).strftime("%Y-%m-%d") )

print(date_list)    
# ['2021-01-01', '2021-02-01', '2021-03-01', '2021-04-01', '2021-05-01']
Posted by: Guest on May-21-2021
0

add a string to each element of a list python

my_list = ['foo', 'fob', 'faz', 'funk']
string = 'bar'
list2 = list(map(lambda orig_string: orig_string + string, my_list))
Posted by: Guest on August-28-2020

Code answers related to "how to add items to a list with a loop python"

Python Answers by Framework

Browse Popular Code Answers by Language