I am iterating over a list in a scripting language, here using python.
Say, I want to generate the string "list(), list(), list()".
Something gets added to the brackets of "list(....)" but that's not important.
I need to treat the first Element differently, as I don't add a comma (",") before the word list then.
My Code:
mydict = {"r": 34, "i": 56, "k" : 99}
s = ""
listOfKeys = list()
firstInList = True
for key, value in mydict.iteritems() :
listOfKeys.append(key)
if firstInList:
firstInList = False
else:
s += ","
s += "list("
#
# more code that is not relevant to the question ...
#
s += ")"
print s
Now when I have nested lists the approach gets messy. How do I solve that better in python?