This task is part of test which is due at 23:59 EST on 2022-01-01.
This is an individual task.
Put all of your work for this task into the file
files.py
(you will create this file from scratch)
This task involves writing three functions: listFile, grep, and
addRecords.
listFile prints each line of a target file, along with line numbers.grep reads lines from one file, finds those that contain a certain
string fragment, and then writes those to a second file.addRecords appends lines to a file based on a list of strings, adding
a newline character to the end of each string as it writes into the
file so that they appear as different lines.Note that these tests do not clean up created files, as it's assumed that the entire sandbox will be cleaned up at some point.
listFile examples
These examples show how listFile should work on the birds and fish
lists provided with the starter code.
In []:PrintslistFile('birds.txt')1 tern 2 albatross 3 seagull 4 sparrow 5 cardinal 6 oriole 7 robin 8 swallow 9 stork 10 cassowary 11 ostrich 12 chicken 13 tanager 14 goose 15 turkey 16 quail 17 chickadee 18 nuthatchIn []:PrintslistFile('fish.txt')1 tuna 2 swordfish 3 sawfish 4 sunfish 5 mackerel 6 anchovy 7 flying fish 8 angler fish 9 lantern fish 10 salmon 11 carp 12 catfish
grep examples
These examples show how grep should work on the birds and fish
lists provided with the starter code.
In []:Filegrep('birds.txt', 'er', 'birds.txt.er')birds.txt.ertern tanagerIn []:Filegrep('fish.txt', 'er', 'fish.txt.er')fish.txt.ermackerel angler fish lantern fishIn []:Filegrep('dir/mammals.txt', 'er', 'dir/mammals.txt.er')dir/mammals.txt.erpanther
grep returns the correct result
grep function is run must match the solution result.listFile prints the correct output
listFile function is run must match the solution output.addRecords writes the correct data into records.txt
records.txt when your addRecords function is run must match what the solution writes.