日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python 程序:檢查兩個(gè)字符串是否是異序詞

創(chuàng)新互聯(lián)python教程:

寫(xiě)一個(gè) Python 程序來(lái)檢查兩個(gè)字符串是否是異序詞。例如,如果一個(gè)字符串通過(guò)重新排列其他字符串字符而形成,則它是一個(gè)異序詞字符串。例如,三角形和積分都將通過(guò)重新排列字符而形成。

在本 Python 示例中,sorted 方法按字母順序?qū)蓚€(gè)字符串進(jìn)行排序,if 條件檢查兩個(gè)排序后的字符串是否相等。如果為真,則兩個(gè)字符串是異序詞。

str1 = input("Enter the First String  = ")
str2 = input("Enter the Second String = ")

if(sorted(str1) == sorted(str2)):
    print("Two Strings are Anagrams.")
else:
    print("Two Strings are not Anagrams.")

Enter the First String  = listen
Enter the Second String = silent
Two Strings are Anagrams.

Python 程序檢查兩個(gè)字符串是否是異序詞或者沒(méi)有使用集合庫(kù)中的計(jì)數(shù)器。

from collections import Counter

str1 = input("Enter the First String  = ")
str2 = input("Enter the Second String = ")

if(Counter(str1) == Counter(str2)):
    print("Two Strings are Anagrams.")
else:
    print("Two Strings are not Anagrams.")
Enter the First String  = race
Enter the Second String = care
Two Strings are Anagrams.

Enter the First String  = dare
Enter the Second String = care
Two Strings are not Anagrams.

網(wǎng)站題目:Python 程序:檢查兩個(gè)字符串是否是異序詞
分享路徑:http://m.5511xx.com/article/dhspdhd.html