我有两个文本文件“usernames.txt”和“passwords.txt”,我想让它们按照特定的顺序打印出来,我有一段代码完全符合我的需要,但我觉得它可以是缩短。如何减少此代码?
with open('passwords.txt','r') as f:
for line in f:
for password in line.split():
with open('usernames.txt','r') as f:
for line in f:
for username in line.split():
print username +":"+ password
这对我来说很完美,我觉得我可以让它变得更短!
电流输出是这样的:
username1:password
username1:password1
username1:password2
username2:password
username2:password1
username2:password2
显示用于生成样品的输入文件输出。 – John1024
有关改进或维护代码的问题应在[CodeReview](https://codereview.stackexchange.com/)上发布。 –