Python: Nested Loop
问题 Consider this: >>> a = [("one","two"), ("bad","good")] >>> for i in a: ... for x in i: ... print x ... one two bad good How can I write this code, but using a syntax like: for i in a: print [x for x in i] Obviously, This does not work, it prints: ['one', 'two'] ['bad', 'good'] I want the same output. Can it be done? 回答1: >>> a = [("one","two"), ("bad","good")] >>> print "\n".join(j for i in a for j in i) one two bad good >>> for i in a: ... print "\n".join(i) ... one two bad good 回答2: List