runtime
188 / 500
question 188 Files & Directories · hard

Find duplicate uploads

People upload the same file again and again under different names (orders (2).csv, copy of orders.csv). Find the groups of files in a folder whose contents are exactly the same, byte for byte, so the copies can be cleaned up.

Functionduplicate_groups(folder)
Comparethe files' bytes: path.read_bytes(); two files with the same size but different bytes are not duplicates
Returnsa list of groups; each group is a sorted list of file names (2 or more) with identical contents; groups are sorted by their first name; [] when there are no duplicates
Ignoresub-folders and the files inside them
Examples
callduplicate_groups('uploads')returns[['a_orders.csv', 'copy of orders.csv', 'orders (2).csv'], ['notes-final.txt', 'notes.txt']]
callduplicate_groups('unique')returns[]
callduplicate_groups('blanks')returns[['one.txt', 'two.txt']]

Loading your progress…

Find duplicate uploads — Python practice · Runtime