如何将这个 python print 函数的每一行写入字符串列表?
我有...
>>> for i in range(11):
... for j in range(103):
... print "./", '%02d' % i, "/IMG", '%04d' % j, ".jpg"
...
>>> (prints a whole bunch of lines representing files in a group of directories)
...而我想要的是将这些行中的小字符串和整数连接成单个字符串,并将其附加到一个包含大约 1100 个元素的列表,每个元素都是一个文件的名称。我该如何修改循环?
I have...
>>> for i in range(11):
... for j in range(103):
... print "./", '%02d' % i, "/IMG", '%04d' % j, ".jpg"
...
>>> (prints a whole bunch of lines representing files in a group of directories)
...and what I want instead is to concatenate the little strings and ints in those lines into single strings, and append it to a list which will comprise approximately 1100 elements, each of which is the name of a file. How can I amend the loop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ITYM
或者更短,
ITYM
or, shorter,
或稍快(~6%)但更混乱
or slightly(~6%) faster but more obfuscated