Splitting list items and adding value to them in python
<p>I want to split list items then add values to them. To do this I am required to take the first sentence; split it into a list; use the <code>isdigit()</code> to determine if the list element is a digit then add 1 to the element; join the new list elements together using <code>join()</code>. It needs to be done using the for loop with enumerate. </p>

<p>This is my code :</p>

<pre><code>a="You would like to visit "+li[0]+" as city 1 and " +li[1]+ " as city 2 and "+li[2]+" as city 3 on your trip"      
print a
printer = a.split(" ")
print printer
if printer.isdigit():
</code></pre>

<p>Here is another way to look at solution <em>(with comments added)</em></p>

<pre><code>li = ["New York", "London", "Tokyo"] #This is an example list for li

a="You would like to visit "+li[0]+" as city 1 and " +li[1]+ " as city 2 and "+li[2]+" as city 3 on your trip"      
print a
printer = a.split(" ")
print printer

new_printer = []
for word in printer:
    if word.isdigit():
        word = str(int(word) + 1) #this increments word by 1. first we have to convert the string value of word to number (int) and then add one (+ 1), and then convert it back to a string (str) and save it back to word
    new_printer.append(word) # this adds word (changed or not) at the end of new_printer
end_result = " ".join(new_printer) #this joins all the words in new_printer and places a space between them

print end_result
</code></pre>

<p>Good luck!</p>

python