I have a list that looks something like this:
days_list = ['12','554','43','2343','52']
How do I modify it so that it looks like this: days_list = ['days:12', 'days:554', 'days:43', 'days:2343', 'days:52']
?
I have a list that looks something like this:
days_list = ['12','554','43','2343','52']
How do I modify it so that it looks like this: days_list = ['days:12', 'days:554', 'days:43', 'days:2343', 'days:52']
?
Make a new list, based on the old, where each element is a string with prefix "days:" and then the original value.
days_list = ['days:{}'.format(value) for value in days_list]
Using list comprehension you can do this easily
result = ['days:'+item for item in days_list]
Write the code as:
days_list = ['days:{}'.format(value) for value in days_list]
or
days_list = [f'days:{value}' for value in days_list]
or
days_list = [f'days:{days_list[x]}' for x in range(0, len(days_list))