On 30/07/18 19:11, Zachary Ware wrote:
> On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote:
>> There are lots of options including those suggested elsewhere.
>> Another involves using get() which makes your function
>> look like:
>>
>> def viceversa(d):
>> new_d = dict()
>> for k
On Mon, Jul 30, 2018 at 1:08 PM Alan Gauld via Tutor wrote:
> There are lots of options including those suggested elsewhere.
> Another involves using get() which makes your function
> look like:
>
> def viceversa(d):
> new_d = dict()
> for k in d:
> for e in d[k]:
> new
On 30/07/18 13:40, Valerio Pachera wrote:
> users = {'user1':['office-a', 'office-b'],
> 'user2':['office-b'],
> 'user3':['office-a','office-c']}
>
> It's a list of users.
> For each user there's a list of room it can access to.
>
> I wish to get the same info but "sorted" by room.
Re
Zachary Ware wrote:
> On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote:
>> I was looking to substiture the cicle for e in new_d like this:
>> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in
>> [ d[k] ]
>> but it can't work because 'new_d[e] = []' is missing.
>
> Hav
On Mon, Jul 30, 2018 at 12:20 PM Valerio Pachera wrote:
> I was looking to substiture the cicle for e in new_d like this:
> [ new_d[e].append(k) if e in new_d else new_d[e].append(k) for e in d[k] ]
> but it can't work because 'new_d[e] = []' is missing.
Have a look at `dict.setdefault` and pla
Hi all, consider this dictionary
users = {'user1':['office-a', 'office-b'],
'user2':['office-b'],
'user3':['office-a','office-c']}
It's a list of users.
For each user there's a list of room it can access to.
Generalizing, a dictionary with a list for each element.
d = {k:list}
I wi