[Tutor] most efficient way to do this
Christopher Spears
cspears2002 at yahoo.com
Fri Feb 15 01:10:53 CET 2008
I created a file called arrays.py:
#!/usr/bin/python
locations = ["/home/",
"/office/" ,
"/basement/" ,
"/attic/"]
Now I want to add the word "chris" on to each element
of the locations list, so I wrote another script
called chris_arrays.py:
#!/usr/bin/python/
from arrays import locations
add_on = "chris"
new_loc = []
for i in range(len(locations)):
new_loc.append(locations[i] + add_on)
print new_loc
Is this the most efficient way to do this? I'm using
these scripts to test some changes I want to make to a
script at work. Basically, I want one file to hold a
list of paths. The other file imports the list and
then asks the user for input that it then adds on to
each string in the list. I want the paths to be in a
separate file, so I can access these paths with
different scripts.
More information about the Tutor
mailing list