【发布时间】:2018-02-02 20:27:42
【问题描述】:
我有三个字符串:s1、s2 和 edit action。它们如下所示:
s1 = kevin josh left at three for - car.
s2 = kevin - left at one - for his car.
edit action = d s i
我想像这样对齐它们:
s1 = kevin josh left at three for - car.
s2 = kevin - left at one for his car.
edit action = d s i
下面是我的代码,我使用了 format 和 join 来将它们对齐:
print(" s1 = ", '{0}'.format(" ".join(s1)))
print(" s2 = ",'{0}'.format(" ".join(s2)))
print("edit action = ",'{0}'.format(" ".join(edit action)))
【问题讨论】:
-
d、s和i与josh和-、three和one和-和 @987654333355 有什么关系? /跨度> -
它们是将字符串 s1 转换为字符串 s2 所需的操作。 d代表删除一个词,s代表或替换一个词,i代表插入一个词。
标签: python python-3.x join format