0

I'm suppose to store all words in a long sentence in a binary tree stored in a txt.file

Ex english.txt: A blurb or a tag is a statement about a book, record or video, supplied by the publisher or distributor, like "The best-selling novel" or "Greatest hit tunes" or even "Perverse sex".

How do I story every single word of the sentence in the tree?

I have tried:

from bintreeFile import Bintree
english = Bintree()
with open("english.txt", "r", encoding = "utf-8") as english_file:
for rad in english_file:
    words = rad.strip().split(" ")
    engelska.put(words)
    engelska.write()

This ends up printing ex:

['A', 'blurb', 'or', 'a', 'tag', 'is', 'a', 'statement', 'about', 'a', 'book,']
['record', 'or', 'video,', 'supplied', 'by', 'the', 'publisher', 'or']

How can i fix this so it only prints the words?

A
blurb
or
tag
...etc
macropod
  • 12,757
  • 2
  • 9
  • 21
  • It seems like there are two questions here: one about inserting words in a tree, and one about printing elements from a list. It would be ideal if you could stick to one of these questions. – Ben Grossmann Sep 16 '22 at 16:11

1 Answers1

0

engelska is probably a list or an Array of some sort. Arrays/Lists have iterable methods, so you need to do something like

for x in engelska:
       print(x)
this
  • 191
  • 13