fix: most_used_key
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
from lektor.reporter import reporter, style
|
from lektor.reporter import reporter, style
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Dict
|
||||||
from itertools import groupby
|
|
||||||
|
|
||||||
|
|
||||||
def report_config_error(key: str, field: str, val: str, e: Exception) -> None:
|
def report_config_error(key: str, field: str, val: str, e: Exception) -> None:
|
||||||
@@ -19,9 +18,11 @@ def most_used_key(keys: List[str]) -> str:
|
|||||||
return keys[0] # TODO: first vs last occurrence
|
return keys[0] # TODO: first vs last occurrence
|
||||||
best_count = 0
|
best_count = 0
|
||||||
best_key = ''
|
best_key = ''
|
||||||
for key, itr in groupby(keys):
|
tmp = {} # type: Dict[str, int]
|
||||||
count = sum(1 for i in itr)
|
for k in keys:
|
||||||
if count > best_count: # TODO: (>) vs (>=), first vs last occurrence
|
num = (tmp[k] + 1) if k in tmp else 1
|
||||||
best_count = count
|
tmp[k] = num
|
||||||
best_key = key
|
if num > best_count: # TODO: (>) vs (>=), first vs last occurrence
|
||||||
|
best_count = num
|
||||||
|
best_key = k
|
||||||
return best_key
|
return best_key
|
||||||
|
|||||||
Reference in New Issue
Block a user