Skip to content

Commit

Permalink
fix: replace list(set()) with list(dict.fromkeys())
Browse files Browse the repository at this point in the history
Use list(dict.fromkeys()) instead of list(set()) to ensure the list
  • Loading branch information
zhangyu94 committed Aug 24, 2023
1 parent c894edc commit 1ad3268
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_tags(field_values: List[Dict]) -> List[str]:
"Data Visualization",
]
tags = [d for d in tags if d not in useless_tags]
return list(set(tags))
return list(dict.fromkeys(tags))


def get_abstract(field_values: List[Dict]) -> Union[str, None]:
Expand Down
8 changes: 4 additions & 4 deletions libprocess/gallica/_process_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def get_authors(record: Record) -> Union[List[str], None]:
creator = get_english_attr(record, "dc:creator")
if creator is None:
return None
return list(set(get_english_attr(record, "dc:creator")))
return list(dict.fromkeys(creator))


def get_publish_date(record: Record) -> Union[TimePoint, None]:
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_languages(record: Record) -> List[str]:
}
languages = [language_map[d] if d in language_map else d for d in languages]

return list(set(languages))
return list(dict.fromkeys(languages))


def get_tags(record: Record) -> List[str]:
Expand All @@ -180,7 +180,7 @@ def get_tags(record: Record) -> List[str]:
"view",
]
tags = [d.title() for d in tags if d not in useless_tags]
return list(set(tags))
return list(dict.fromkeys(tags))


def get_abstract(record: Record) -> Union[str, None]:
Expand Down Expand Up @@ -209,7 +209,7 @@ def get_rights(record: Record) -> str:
if rights is None:
return "unknown"

rights = list(set(get_english_attr(record, "dc:rights")))
rights = list(dict.fromkeys(rights))
assert len(rights) == 1, f"Unexpected rights with length != 1: {rights}"

if rights == "public domain":
Expand Down
2 changes: 1 addition & 1 deletion libprocess/internet_archive/_process_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_tags(source_data: SourceData) -> List[str]:
parts = [d.lstrip("* ").rstrip("; ").title() for d in tag.split(";")]
tags += [d for d in parts if d != "" and not is_name(d)]

return list(set(tags))
return list(dict.fromkeys(tags))


def get_languages(source_data: SourceData) -> Union[List[str], None]:
Expand Down
4 changes: 2 additions & 2 deletions libprocess/library_of_congress/_process_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_languages(source_data: SourceData) -> List[str]:
parsed += matched
else:
parsed.append(d)
return [*set(parsed)]
return list(dict.fromkeys(parsed))


def get_abstract(source_data: SourceData) -> Union[str, None]:
Expand Down Expand Up @@ -220,7 +220,7 @@ def get_rights(source_data: SourceData) -> str:
if "rights_information" in item:
rights.append(item["rights_information"])

rights = [*set(rights)]
rights = list(dict.fromkeys(rights))

assert len(rights) <= 1, f"Unexpected rights with length > 1: {rights}"

Expand Down

0 comments on commit 1ad3268

Please sign in to comment.