i=0
for db in dflist:
db.columns = [varName.replace(yearEndList[i], "") for varName in db.columns]
i = i + 1
I also wanted to change the names to lower case. Again, no big problem:
db.columns = [varName.lower() for varName in db.columns]
But I kept wondering whether it could be done more elegantly. Both replace and upper at the same time, not sequentially- in an elegant and fast way. A for loop could do this, for instance something similar to this seems natural:
for varName in db.columns
replace(yearEndList[i], "")
upper()
It is implicit that we are doing tings with the variable in the loop.
Perhaps there is no similarly easy readable way to do multiple changes with list comprehension. Yes, it can be done, but not very elegantly, or?