how to prepend string to a string?
Kent Johnson
kent37 at tds.net
Mon May 30 22:27:40 EDT 2005
flamesrock wrote:
> so I know you can append a string. But how do you *prepend* a string,
> as shown in the following code
>
> #dirList = ['depth1','depth2','depth3']
> #string = """position"""
> #for x in len(dirList):
> # string += '>> %s'%dirList.pop() #(????????????)
> #
>
> to return
> position>> depth1 >> depth2 >> depth3
ISTM the problem is not prepending, but getting the elements of dirList in the order you want. If
you iterate over the list normally you get the desired result:
dirList = ['depth1','depth2','depth3']
string = """position"""
for x in dirList:
string += '>> %s'% x
Kent
More information about the Python-list
mailing list