English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
この問題を解決するために、リクエストモジュールが必要です。
リクエストモジュールをインストールするには、コマンドラインで以下のコマンドを実行する必要があります。
スクレイピング
リクエストモジュールをインポートします。
その後、URLからデータを取得する必要があります。
UTFを使用して-8テキストをデコードします。
次に、文字列を単語リストに変換します。
単語リストをループで巡ります。
次に、各単語の相邻文字のASCII値を比較します。
比較が正確であれば、並び順のある単語を印刷し、それ以外の場合、並び順のない単語を保存します。
import requests def Words_find(): my_url = ""#put thisurl of .txt files in any website my_fetchData = requests.get(my_url) my_wordList = my_fetchData.content my_wordList = my_wordList.decode("utf-8").split() return my_wordList def wordordered(): collection = Words_find() collection = collection[16:] my_word = '' for my_word in collection: result = 'ordered' i = 0 l = len(my_word) - 1 if (len(my_word) < 3): continue while i < l: if (ord(my_word[i]) > ord(my_word[i+1)): result = 'not ordered' break else: i += 1 if (result == 'ordered'): print(my_word, ': ', result) if __name__ == '__main__': wordordered()