Creating custom struct/map and adding to list issue

for does not leak inner bindings to the outer world, thats why teams_with_scores is not available outside.

As you have it now, your code is free of side effects (ignoring the inspect which is for debugging only, I assume), so you could remove the for without changing the observable behaviour of your program.

If I understand you correctly, what youz actually want is this:

# with comprehension
teams_with_scores = for team <- teams do
  %{name: team.name, team_score: get_team_score(team)}
end

# using `Enum.map/2`
teams_with_scores = Enum.map(teams, fn team ->
  %{name: team.name, team_score: get_team_score(team)}
end

Just replace everything of your code beginning with teams_with_scores = [] and endingwith the IO.inspect(teams_with_scores) with one of my suggestions.