I am new to Python and had a question about updating a list using a for loop. Here is my code:
urls = ['http://www.city-data.com/city/javascript:l("Abbott");' , 'http://www.city-data.com/city/javascript:l("Abernathy");' ,
'http://www.city-data.com/city/Abilene-Texas.html' ,'http://www.city-data.com/city/javascript:l("Abram-Perezville");' ,
'http://www.city-data.com/city/javascript:l("Ackerly");' , 'http://www.city-data.com/city/javascript:l("Adamsville");',
'http://www.city-data.com/city/Addison-Texas.html']
for url in urls:
if "javascript" in url:
print url
url = url.replace('javascript:l("','').replace('");','-Texas.html')
print url
for url in urls:
if "javascript" in url:
url = url.replace('javascript:l("','').replace('");','-Texas.html')
print "\n"
print urls
I used the first for loop to check if the syntax was correct, and it worked fine. But the second for loop is the code I want to use, but it's not working properly. How would I go about globally updating the list with the second for loop so I can print or store the updated list outside of the for loop?