Skip to content
Advertisement

Create list of list tuples from reading a txt file

I have a txt file that look likes

JavaScript

And Im trying to make a tuples from this txt which ı will evalute them laterly word to features later on. I want to have a list of list look like this :

JavaScript

All of the whitespaces indicates that the sentences over and should add to list to given index, laterly after whitespace we should move on the next index of the list to add all sentences.

JavaScript

I have a function like this however it return this:

JavaScript

How can ı solve this problem, ı use 2 different list to add them together but ı could not find a way.

Advertisement

Answer

I think all problem is because you show expected result

JavaScript

but I think you expect

JavaScript

and this need

JavaScript

At the end it may need also to add last data becuase there is no empty line after these data

JavaScript

Full working example.

I use io only to simulate file in memory so everyone can copy and run it. But you should use open() without text.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement