程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How can they connect? Python3 Cartesian product and find letter replacement text?

編輯:Python
from itertools import productL1 = list("abcd")L2 = list("+-*/")L3 = list("x")L4 = list("=><≈")L5 = list("1")l = []for X2,X3,X4,X5,X1 in product(L2,L3,L4,L5,L1): s = X1+X2+X3+X4+X5 l.append(s.replace(" ", ""))n = 1for i in l: if n%4 == 0: print(i) else: print(i, end ='') n = n + 1

Not connected in the middle , How equal to n The result of cyclic Cartesian product ?

f=lprint(f,end = "\t")
a = ["a", "b"] # Ready to find replacement words b = [" One ", " I "] # The replacement  import re # Import library dic = dict(zip(a,b)) # Replace dictionary pattern = re.compile('(' + '|'.join(a) + ')')s = pattern.sub(lambda g:dic[g.group()],k)print(s)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved