input: Write a function in Python that takes a list of dictionaries and a string representing the key of the attribute by which to sort the list. The function should return the sorted list of dictionaries based on the specified attribute.
  
  assert sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "age") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Eve", "age": 10}, {"name": "Dan", "age": 19}, {"name": "Charlie", "age": 3}], "age") == [{"name": "Charlie", "age": 3}, {"name": "Eve", "age": 10}, {"name": "Dan", "age": 19}]
  assert sort_by_attr([{"name": "Bob", "score": 95}, {"name": "Alice", "score": 90}], "score") == [{"name": "Alice", "score": 90}, {"name": "Bob", "score": 95}]
  assert sort_by_attr([], "age") == []
output: def sort_by_attr(lst, key):
      return sorted(lst, key=lambda x: x.get(key))