Common Lines

Created on April 10, 2025 by Julien Palard

Write a program that searches for common lines between multiple given files.

Your program accepts file names as parameters in sys.argv).

Example:

1
2
$ python common-lines.py file1.txt file2.txt
Hello world

If no file are given, your program must print some help, then exit with a return code greater than zero.

If no lines are common between the given files, your program must exit with an error code greater than zero.

The line order can be ignored: if a file a contains:

1
2
Hello
world

and a file b contains:

1
2
world
Hello

then they have two common lines, and you program can either print:

1
2
Hello
world

or:

1
2
world
Hello

both are valid.

If more than two files are given, your program must print lines common to all files, example :

If the file a contains:

1
2
3
Hello
world
!

The file b:

1
2
Hello
world

And the file c:

1
2
Hello
!

Then python common-lines.py a b c should only print Hello.

Empty lines must be ignored.

File will always be encoded using UTF-8.

If any given name points to an existing file, or to a file that cannot be decoded using UTF-8, your program must print an error message an exit with a return code greater than zero.

  • There's no corrections yet, hit the `Submit` button to send your code to the correction bot.
  • Keyboard shortcuts:
    • Ctrl-Enter: Send your code to the correction bot.
    • Escape: Get back to the instructions tab.
(Ctrl-Enter)