Which of the following is better to use and why?
Method 1:
for k, v in os.environ.items():
print \"%s=%s\" % (k, v)
Method 2
I agree with @Ben, @Tim, @Steven:
Example:
print "\n".join("%s=%s" % (k, v) for k,v in os.environ.iteritems())
in the code snippet above, I made two changes... I replaced the listcomp with a genexp, and I changed the method call to iteritems(). [this trend is moving forward as in Python 3, iteritems() replaces and is renamed to items().]