Aug-11-2018, 09:19 AM
I had just started with Python and run into this task:
1.Find words that exists on both even and odd lines.
2.Words that only exists on even lines
3.Words that only exists on odd lines
All punctuations and uppercase is removed so we dont need to worry about that. However it is several words on the same line
The output should look something like this
Common words on both lines: ['I', 'the', 'am', 'all', 'as', ...]
Only even lines : ['yellow', 'christmas', 'smell', ...]
Only odd lines: ['yours', 'war', 'may', 'remote', ...]
I started like
Would love if someone could finish the task so I could use it as a template when I do other tasks.
1.Find words that exists on both even and odd lines.
2.Words that only exists on even lines
3.Words that only exists on odd lines
All punctuations and uppercase is removed so we dont need to worry about that. However it is several words on the same line
The output should look something like this
Common words on both lines: ['I', 'the', 'am', 'all', 'as', ...]
Only even lines : ['yellow', 'christmas', 'smell', ...]
Only odd lines: ['yours', 'war', 'may', 'remote', ...]
I started like
evens, odds = set(), set() with open('textfile.txt') as f: for index, row in enumerate(f): if index % 2 == 0: evens.add(row.strip()) else: odds.add(row.strip())How should I continue from here? Is this part correct?
Would love if someone could finish the task so I could use it as a template when I do other tasks.