我有三根弦:
strand1 = "something"
strand2 = "something else"
strand3 = "something else again"
我想在这3个字符串的每个可能排列上运行一些函数,例如:
案例1:
strand1 = "something else again"
strand2 = "something"
strand3 = "something else"
案例2
strand1 = "something else"
strand2 = "something else again"
strand3 = "something"
等等。。。你知道吗
在Python中如何优雅地做到这一点?我考虑过将字符串放入数组中并使用itertools
,但它似乎会在每次迭代时剪切字符串。你知道吗
另一件需要考虑的事情是字符串存储在对象中。例如,我通过键入
strand1.aa
谢谢你的帮助,我希望问题是清楚的。你知道吗
您可以使用^{} 。如果函数有多个参数,可以通过splat operator传递它们。你知道吗
输出:
itertools
是一个合适的地方。你试过itertools.permutations
吗?你知道吗查看documentation for it。你知道吗
在
itertools.permutations(iterable)
方法中的某些东西会给您一个置换生成器,然后您可以使用for循环来处理每个置换。你知道吗此样本产生
相关问题 更多 >
编程相关推荐