whitelist = {"id", "name"} filtered = {k: v for k, v in data.items() if k in whitelist} print(filtered) # {'id': 1, 'name': 'Alice'}
// Whitelist const whitelist = ["id", "name"]; const filtered = Object.fromEntries( Object.entries(data).filter(([key]) => whitelist.includes(key)) ); console.log(filtered); // { id: 1, name: "Alice" } filters keys
const data = { id: 1, name: "Alice", age: 30, role: "admin" }; whitelist = {"id", "name"} filtered = {k: v for k, v in data
The proper article for "filters keys" could depend on the context in which you're using the phrase. However, if you're referring to the concept in a general sense or as a heading/title, no article might be needed: . whitelist = {"id"
In general, though, (without an article) works well in many contexts: