Pra4-working_with_files

In this Practice, we will learn how to input/output a file

sample_dataset = open('../file_inputs/rosalind_ini5.txt', 'r')


# Trying to test how len() and range() will influence output
read_sample_lines = sample_dataset.readlines()
print(read_sample_lines)
print(len(read_sample_lines))
print(range(len(read_sample_lines)))

# Create empty output file first
sample_dataset_output = open('rosalind_ini5_output.txt', 'w')

# Using loop to get each even line 
for i in range(len(read_sample_lines)):
    if i % 2 != 0:
        print(read_sample_lines[i].strip())
        sample_dataset_output.write(str(read_sample_lines[i].strip()) + '\n')
['`Twas brillig, and the slithy toves\n', 'Some things in life are bad, they can really make you mad\n', '  Did gyre and gimble in the wabe:\n', 'Other things just make you swear and curse\n', 'All mimsy were the borogoves,\n', "When you're chewing on life's gristle, don't grumble give a whistle\n", '  And the mome raths outgrabe.\n', 'This will help things turn out for the best\n', '"Beware the Jabberwock, my son!\n', 'Always look on the bright side of life\n', '  The jaws that bite, the claws that catch!\n', 'Always look on the right side of life\n', 'Beware the Jubjub bird, and shun\n', "If life seems jolly rotten, there's something you've forgotten\n", '  The frumious Bandersnatch!"\n', "And that's to laugh and smile and dance and sing\n", 'He took his vorpal sword in hand:\n', "When you're feeling in the dumps, don't be silly, chumps\n", '  Long time the manxome foe he sought --\n', "Just purse your lips and whistle, that's the thing\n", 'So rested he by the Tumtum tree,\n', 'So, always look on the bright side of death\n', '  And stood awhile in thought.\n', 'Just before you draw your terminal breath\n', 'And, as in uffish thought he stood,\n', "Life's a counterfeit and when you look at it\n", '  The Jabberwock, with eyes of flame,\n', "Life's a laugh and death's the joke, it's true\n", 'Came whiffling through the tulgey wood,\n', "You see, it's all a show, keep them laughing as you go\n", '  And burbled as it came!\n', 'Just remember the last laugh is on you\n', 'One, two! One, two! And through and through\n', 'Always look on the bright side of life\n', '  The vorpal blade went snicker-snack!\n', 'And always look on the right side of life\n', 'He left it dead, and with its head\n', 'Always look on the bright side of life\n', '  He went galumphing back.\n', 'And always look on the right side of life\n']
40
range(0, 40)
Some things in life are bad, they can really make you mad
Other things just make you swear and curse
When you're chewing on life's gristle, don't grumble give a whistle
This will help things turn out for the best
Always look on the bright side of life
Always look on the right side of life
If life seems jolly rotten, there's something you've forgotten
And that's to laugh and smile and dance and sing
When you're feeling in the dumps, don't be silly, chumps
Just purse your lips and whistle, that's the thing
So, always look on the bright side of death
Just before you draw your terminal breath
Life's a counterfeit and when you look at it
Life's a laugh and death's the joke, it's true
You see, it's all a show, keep them laughing as you go
Just remember the last laugh is on you
Always look on the bright side of life
And always look on the right side of life
Always look on the bright side of life
And always look on the right side of life