首先,我知道有很多類似的帖子我已經在下面列出,但是,沒有人知道我回答的問題是面對這是因爲我發現的所有問題都是如何在'dict.values()'中搜索一個字符串,而不是搜索字符串中的每個字符,並檢查它是否在'dict.values()'和如果它在'dict.values()'的字符中出現的字符串中找到任何字符,它將返回哪些字符和多少字符。如何從一個字符串中搜索所有字符Dictionary.Values()
鏈接到類似的職位不回答這個問題,但可能是有用的一些:
How to search if dictionary value contains certain string with Python
Find dictionary items whose key matches a substring
How can I check if the characters in a string are in a dictionary of values?
How to search if dictionary value contains certain string with Python
這是我迄今爲止,但似乎沒有工作...
characters = {'small':'abcdefghijklmnopqrstuvwxyz',
'big':'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'nums':'',
'special':"!#$%&()*+,-./:;<=>[email protected][\]^_{|}~",}
password = 'aAb'
def count(pass_word,char_set):
num_of_char = 0
char_list = []
for char in pass_word:
if i in char_set.values():
num_of_char +=1
char_list += i
return char_list, num_of_char
#Print result
print(count(password,characters))
輸出應該類似於:
'a','A','b'
3
希望你明白我的意思,如果有什麼不清楚的,請發表評論,這樣我就可以改善。
不好意思問,但什麼ü平均組件明智的即時通訊新張貼和從來沒有碰到過這句話 – Ivan
不用擔心他,所有你需要做的就是提供相關的標籤,你所做的。如果他不想閱讀帖子,就擰他。 – postoronnim
; D好的,謝謝 – Ivan