<div dir="ltr"><div class="gmail_quote"><div>I think you cheated a little in your cut-and-paste. `<font face="monospace, monospace">student_by_school</font>` is not defined in the code you've shown. What you *<b>did</b>* define, `<font face="monospace, monospace">student_school_list`</font> doesn't give you what you want if you use `<span style="font-family:monospace,monospace;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">defaultdict(list,student_school_list)`</span><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="arial, helvetica, sans-serif">.</font></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><font face="arial, helvetica, sans-serif">I thought for a moment I might just use:</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_quote"><div><font face="monospace, monospace">[(b,a) for a,b in student_school_list]</font></div></div></blockquote><div class="gmail_quote"><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">But that's wrong for reasons that are probably obvious to everyone else. I'm not really sure what `<span style="font-family:monospace,monospace;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">student_by_school`</span><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> could possibly be to make this work as shown.</span></font></div><div dir="ltr"><br></div><div dir="ltr">On Thu, Jun 28, 2018 at 8:13 PM Chris Barker via Python-ideas <<a href="mailto:python-ideas@python.org">python-ideas@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><span style="font-family:monospace,monospace">In [97]: student_school_list</span><br></div><div><div><font face="monospace, monospace">Out[97]: </font></div><div><font face="monospace, monospace">[('Fred', 'SchoolA'),</font></div><div><font face="monospace, monospace"> ('Bob', 'SchoolB'),</font></div><div><font face="monospace, monospace"> ('Mary', 'SchoolA'),</font></div><div><font face="monospace, monospace"> ('Jane', 'SchoolB'),</font></div><div><font face="monospace, monospace"> ('Nancy', 'SchoolC')]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [98]: result = defaultdict(list, student_by_school)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [99]: result.items()</font></div><div><font face="monospace, monospace">Out[99]: dict_items([('SchoolA', ['Fred', 'Mary']), ('SchoolB', ['Bob', 'Jane']), ('SchoolC', ['Nancy'])])</font></div></div><div><font face="monospace, monospace"><br></font></div>So: <small voice> never mind </small voice><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">-CHB</font></div><div><br></div></div>-- <br><div class="gmail-m_8594217574281168734gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R (206) 526-6959 voice<br>7600 Sand Point Way NE (206) 526-6329 fax<br>Seattle, WA 98115 (206) 526-6317 main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div></div>