Python 程式,用於在字串中查詢頻率最低的字元
當需要在字串中查詢頻率最低的字元時,‘Counter’用於獲取字母的計數。“min”方法用於獲取字串中的最小值,即記錄每個字母的計數。獲得最小值。
示例
下面演示了同樣的內容
from collections import Counter
my_str = "highland how"
print ("The string is : ")
print(my_str)
my_result = Counter(my_str)
my_result = min(my_result, key = my_result.get)
print ("The minimum of all characters in the string is : ")
print(my_result)輸出
The string is : highland how The minimum of all characters in the string is : a
說明
匯入所需的包。
定義一個字串,並顯示在控制檯上。
‘Counter’用於獲取字串中每個字母的計數。
這分配給一個變數。
“min”方法用於獲取最小值。
這再次分配給變數。
這在控制檯上顯示為輸出。
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP