Created
May 4, 2016 20:21
-
-
Save dance2die/077d824e37e9d8618c62786198492afb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Dictionary<string, List<string>> ConvertToDictionaryOptimized(List<Tuple> actorMovies) | |
{ | |
var result = new Dictionary<string, List<string>>(); | |
foreach (Tuple actorMovie in actorMovies) | |
{ | |
if (result.ContainsKey(actorMovie.Actor)) | |
{ | |
var movies = result[actorMovie.Actor]; | |
movies.Add(actorMovie.Movie); | |
} | |
else | |
{ | |
result.Add(actorMovie.Actor, new List<string> {actorMovie.Movie}); | |
} | |
} | |
return result; | |
} | |
public static Dictionary<string, List<string>> ConvertToDictionary(List<Tuple> actorMovies) | |
{ | |
var result = new Dictionary<string, List<string>>(); | |
foreach (Tuple actorMovie in actorMovies) | |
{ | |
if (result.ContainsKey(actorMovie.Actor)) continue; | |
IEnumerable<Tuple> tempActors = actorMovies.Where(a => a.Actor == actorMovie.Actor); | |
List<string> movies = tempActors.Select(actor => actor.Movie).ToList(); | |
result.Add(actorMovie.Actor, movies); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment