repopick: Fix logic for skipping already merged changes

We can't iterate a list and update it at the same time.

Test: Run `repopick -t XXI` twice
Change-Id: I85651783531b59fd4b48d54a663c22cb243edac7
diff --git a/build/tools/repopick.py b/build/tools/repopick.py
index e41b733..4bdfb9a 100755
--- a/build/tools/repopick.py
+++ b/build/tools/repopick.py
@@ -548,7 +548,7 @@
         mergables[project_path].append(item)
 
     # round 1: start branch and drop picked changes
-    for project_path, per_path_mergables in mergables.items():
+    for project_path in mergables:
         # If --start-branch is given, create the branch (more than once per path is okay; repo ignores gracefully)
         if args.start_branch:
             subprocess.run(["repo", "start", args.start_branch[0], project_path])
@@ -587,7 +587,7 @@
                         picked_change_ids.append(head_change_id.strip())
                         break
 
-        for item in per_path_mergables:
+        def filter_picked(item):
             # Check if change is already picked to HEAD...HEAD~check_picked_count
             if item["change_id"] in picked_change_ids:
                 print(
@@ -595,7 +595,10 @@
                         item["id"], project_path
                     )
                 )
-                per_path_mergables.remove(item)
+                return False
+            return True
+
+        mergables[project_path] = list(filter(filter_picked, mergables[project_path]))
 
     # round 2: fetch changes in parallel if not pull
     if not args.pull: