Can't assign a task to a user

can i assign a user a task where i am fetching the user value from somewhere else because i can’t figure out how to do it through python code?

kindly refer this code to assign a task
def assign():
from frappe.desk.form import assign_to

assign_to.add(
     {
	"assign_to": ["test@example.com"],
	"doctype": task.doctype,
	"name": task.name,
	"description": "Close this task",
     })