<jupyter_start><jupyter_text>Read Contents from URL<jupyter_code>from urllib.request import urlopen

url_response = urlopen('http://www.py4inf.com/code/romeo.txt')

contents = str(url_response.read())

print(contents)<jupyter_output>b'But soft what light through yonder window breaks\nIt is the east and Juliet is the sun\nArise fair sun and kill the envious moon\nWho is already sick and pale with grief\n'<jupyter_text>Split Contents Into Lines Using New-line ('\n')<jupyter_code>lines = contents.split('\\n')

print(lines)<jupyter_output>["b'But soft what light through yonder window breaks", 'It is the east and Juliet is the sun', 'Arise fair sun and kill the envious moon', 'Who is already sick and pale with grief', "'"]<jupyter_text>Extract Words from Each LineNote:  You might have to strip out the `'` character that seems to be slipping through.  My guess is that you'll have to specify a RegEx expression to only accept.<jupyter_code>Jword_set = set()

for line in lines:
    # Passing no args to split() will do what you want in this case:
    #   split on all weird characters (aka whitespace characters)
    words = line.split()
    for word in words:
        # Lowercase the word or else alphabetical sort puts capitals ahead
        word = word.lower()
        # Adding to a set (vs list) will automatically de-duplicate
        word_set.add(word)

print(word_set)
sorted_word_set = sorted(word_set)

print(sorted_word_set)<jupyter_output>["'", 'already', 'and', 'arise', "b'but", 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'it', 'juliet', 'kill', 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through', 'what', 'who', 'window', 'with', 'yonder']
{'fraction_non_alphanumeric': 0.12366230677764566, 'fraction_numerical': 0.0005945303210463733, 'mean_word_length': 4.744027303754266, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '96695', 'license': 'Apache-2.0', 'n_tokens_mistral': 553, 'n_tokens_neox': 539, 'n_words': 198, 'path': 'jupyterhub/notebooks/zz_under_construction/zz_old/Python/Basics/Sets.ipynb', 'repo_name': 'just4jc/pipeline', 'size': '1682'}