Have done some searching through Stack Exchange answered questions but have been unable to find what I am looking for.
Given the following list:
a = [1, 2, 3, 4]
How would I create:
a = ['hello1', 'hello2', 'hello3', 'hello4']
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use a list comprehension:
A list comprehension lets you apply an expression to each element in a sequence. Here that expression is a formatted string literal, incorporating
iinto a string starting withhello.Demo: