<div dir="ltr"><div><div><div><div>import qualified Data.Map as Map<br><br></div><div>-- if your keys are unique<br></div><div>let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item2", ["abc","def"])]<br></div>Map.fromList xs<br><br></div>-- if you want to combine values for keys that are equal<br>let xs = [("Item0", ["a","b","c"]), ("Item1", ["x","y"]), ("Item0", ["abc","def"])]<br></div>Map.fromListWith (++) xs<br><br>--<br></div>Sylvain<br><div><div><div><br></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-11-10 3:07 GMT+01:00 Dan Stromberg <span dir="ltr"><<a href="mailto:strombrg@gmail.com" target="_blank">strombrg@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div>I'm spending a little time here and there to learn some Haskell. I'm coming from a chiefly Python/C/bash background.<div><br></div><div>I want to build a Data.Map where the keys are strings, and the values are lists of strings.</div><div><br></div><div>In Python, collections.defaultdict(list) makes this pretty straightforward. It gives a hash table ("dict") that has values that default to an empty list, since list() produces an empty list. More info here: <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" target="_blank">https://docs.python.org/3/library/collections.html#collections.defaultdict</a></div><div><br></div><div>Is there an equivalent in Haskell?</div><div><br></div><div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div><div><br></div>-- <br><div>Dan Stromberg</div>
</div></font></span></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>