辞書のリストがあり、特定のキーに基づいて一意の値のみを取得したいと考えています。
私が持っているとしましょう
data = [{name: "John", age: "20", occupation: "Python pro"}, \
{name: "Jack", age: "80", occupation: "Olympic Athlete"}, \
{name: "John", age: "20", occupation: "Student"}]
キー「名前」と「年齢」に基づいて減らして、次のように見せたいと思います
[{name: "John", age: "20", occupation: "Python pro"}, \
{name: "Jack", age: "80", occupation: "Olympic Athlete"}]
私は次のことを試しましたが、基本的に毎回すべてを追加するという明白な問題に気づきませんでした。
all_drives = drivesInBuilder("object") + drivesInBuilder("account") + drivesInBuilder("container")
reduced_list = [(x["ip address"], x["name"]) for x in all_drives]
unique_list = list(set(reduced_list))
unique_drives = [x for x in all_drives if (x["ip address"], x["name"]) in unique_list]
print(unique_drives)