update an element of a list

38 Views Asked by At

Say I have a list ["apple", "berry", "cherry", "banana"] . How do I insert additional info into an element so the list becomes something like ["red apple", "red berry", "red cherry", "red banana"] ? The idea is that I change the value of an element just by adding something to the element, without having to name the original value.

Regards, slibbe

1

There are 1 best solutions below

0
ankita On
**Try this**
original_list = ["apple", "berry", "cherry", "banana"]
    additional_list = "red"
    new_list = [additional_list + " " + fruit for fruit in original_list]
    
    print(new_list)