runtime
224 / 500
question 224 CLI & Automation · easy

Check a rename plan before applying it

Before a folder tool applies a rename plan, it lists everything that would go wrong, so a person can fix the plan first. Report each problem pair once, in plan order.

Functionplan_problems(plan, existing)
plana list of (old, new) name pairs
existingthe list of names currently in the folder
Returnsa list of "<old>: <problem>" texts, in plan order; [] when the plan is safe
Problemschecked in this order, first match only: missing source (old isn't in the folder), duplicate target (an earlier pair already renames to the same new name), target exists (new is already in the folder)
Examples
callplan_problems([['Invoice 1.CSV', 'invoice-1.csv'], ['Invoice 2.CSV', 'invoice-2.csv'], ['Invoice 3.CSV', 'invoice-3.csv']], ['Invoice 1.CSV', 'Invoice 2.CSV', 'invoice-2.csv'])returns['Invoice 2.CSV: target exists', 'Invoice 3.CSV: missing source']
callplan_problems([['A.csv', 'a.csv'], ['a .csv', 'a.csv']], ['A.csv', 'a .csv'])returns['a .csv: duplicate target']
callplan_problems([['Q1.PDF', 'q1.pdf']], ['Q1.PDF'])returns[]

Loading your progress…

Check a rename plan before applying it — Python practice · Runtime