How to add a character to the end of every string in a list?

python, python-2.7

Solution

List comprehensions to the rescue!

list = [item + ':' for item in list]

In a list of

['word1', 'word2', 'word3'] 

This will result in

['word1:', 'word2:', 'word3:']

You can read more about them here.

https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions

Problem

Let's say I have a list: ``` list = ["word", "word2", "word3"] ``` and I want to change this list to: ``` list = ["word:", "word2:", "word3:"] ``` is there a quick way to do this?

Original source

Related problems