บทความซ้ำกับ ID 1004106512 ใช้ Counter หา subset ใหญ่สุดของ anagram words
โค้ดตัวอย่าง
from collections import Counter
def largestana(str1):
str1 = str1.split(" ")
for i in range(len(str1)):
str1[i] = ''.join(sorted(str1[i]))
newstr1 = Counter(str1)
print("The Size Of largest subset of Anagram word is:", max(newstr1.values()))
if __name__ == "__main__":
str1 = input("Enter the string: ")
largestana(str1)
ผลลัพธ์
Enter the string: qwe ewq rty ytr ytr ytr The Size Of largest subset of Anagram word is: 4