#!/usr/bin/env python
# -*- coding: utf-8 -*-
def dup_filter(children):
  # childrenと同じ物だけを集めるフィルタ
  def filter(item):
    return set(item['children']) == set(children)
  return filter

def dup_map(item):
  # pathだけを集めるmapper
  return item['path']

def find_duplicates(needle, list):
  # listからneedle(フォルダ)の子供と同じ子供をもつフォルダを集める
  path = needle['path']
  filtered = filter(dup_filter(needle['children']), list)
  dup = map(dup_map, filtered)
  return {'path': path, 'dup': dup}
#   return [
#     {
#       'path': '/fol/hoge/fuga',
#       'dups': [
#         'https://google.com/',
#         'https://google.co.jp/',
#         'https://google.com/?q=some+keywords'
#       ]
#     }
#   ]

def collect_duplicates(list, all):
  # allからlistの先頭要素と重複する物を探し，それとlistの残りの重複を探した物をつなげて返す
  first = list.pop(0)
  found = [find_duplicates(first, all)]
  if list == []:
    return found
  collected = collect_duplicates(list, all)
  found.extend(collected)
  return found

@@ -471,221 +471,8 @@
 dup%7D
-%0A#   return %5B%0A#     %7B%0A#       'path': '/fol/hoge/fuga',%0A#       'dups': %5B%0A#         'https://google.com/',%0A#         'https://google.co.jp/',%0A#         'https://google.com/?q=some+keywords'%0A#       %5D%0A#     %7D%0A#   %5D
 %0A%0Ade
@@ -535,9 +535,13 @@
 %E7%89%A9%E3%82%92%E6%8E%A2%E3%81%97
-%EF%BC%8C
+%0A  # 
 %E3%81%9D%E3%82%8C%E3%81%A8l
@@ -584,16 +584,36 @@
 .pop(0)%0A
+  # %E5%85%88%E9%A0%AD%E8%A6%81%E7%B4%A0%E3%81%A8%E9%87%8D%E8%A4%87%E3%81%99%E3%82%8B%E7%89%A9%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%0A
   found 
@@ -661,16 +661,27 @@
  == %5B%5D:%0A
+    # %E9%87%8D%E8%A4%87%E3%81%AA%E3%81%97%0A
     retu
@@ -689,16 +689,32 @@
 n found%0A
+  # %E6%AE%8B%E3%82%8A%E3%81%AE%E8%A6%81%E7%B4%A0%E3%82%82%E9%87%8D%E8%A4%87%E3%82%92%E6%8E%A2%E3%81%99%0A
   collec

update comments