如何从列中的列表以Python格式打印值?
我把它们分类了,但我不知道怎么用两种方法打印出来 例如:
list=['apricot','banana','apple','car','coconut','baloon','bubble']
第一个:
apricot bubble ...
apple car
baloon coconut
第二条路:
apricot apple baloon
bubble car coconut
我还想把一切都和ljust/rjust联系起来。
我试过这样的方法:
print " ".join(word.ljust(8) for word in list)
但它只显示在第一个例子中。我不知道这样做是否合适。
输出:
更新: 这是一个全面的解决方案,解决了您给出的两个例子。我为此创建了一个函数,并对代码进行了注释,以便清楚地了解它正在做什么。
相关问题 更多 >
编程相关推荐