【发布时间】:2014-08-01 01:51:05
【问题描述】:
我正在尝试查找在第二个字符串中也找到的第一个字符串中的字符数。这是我目前所拥有的:
def main():
text1 = raw_input("Enter word 1: ")
text2 = raw_input("Enter word 2: ")
print("The number of characters that occur in both", text1, "and", text2, "is", count)
def count(text1, text2):
char = 0
for i in text1:
for j in text2:
if i == j:
char += 1
return char
main()
我在使用 def count() 时遇到问题。我不确定如何计算 text1 和 text2 中有多少不会重复的字母。任何帮助表示赞赏!
【问题讨论】:
-
所以你想找出出现在两者中的唯一字符的数量,没有重复?
标签: python