Here is a version that does what you want, while changing a minimal amount
of what you had:
http://pastebin.com/7aF95Lnm

I added another mapping to track the number of items seen per user. That
way when you are iterating your counts you can look up the user and item
name and get the number of items they own.

I am sure there are ways to completely restructure the entire thing, but
given the limited context, this is just one way to change what you already
have.

Justin


On Tue, Feb 14, 2017 at 9:11 PM likage <[email protected]> wrote:

> I have this dictionary.
>
> gen_dict = {
>  "item_C_v001" : "jack",
>  "item_C_v002" : "kris",
>  "item_A_v003" : "john",
>  "item_B_v006" : "peter",
>  "item_A_v005" : "john",
>  "item_A_v004" : "dave"
> }
>
> while I am able to filter out the version makings and the users to:
>
> Item Name     | No. of Vers.      | User
> item_A        | 3                 | dave, john
> item_B        | 1                 | peter
> item_C        | 2                 | jack, kris
>
>
> Currently I am trying to input how many versions each user own so that it
> will be something like this:
>
> Item Name     | No. of Vers.      | User
> item_A        | 3                 | dave(1), john(2)
> item_B        | 1                 | peter(1)
> item_C        | 2                 | jack(1), kris(1)
>
>
> but I am having problems with it.
> This is the code I have used for filtering..
>
> from collections import defaultdict
>
> gen_dict = {
>  "item_C_v001" : "jack",
>  "item_C_v002" : "kris",
>  "item_A_v003" : "john",
>  "item_B_v006" : "peter",
>  "item_A_v005" : "john",
>  "item_A_v004" : "dave"}
>
> user_dict = defaultdict(set)
> count_dict = {}
> for item_name, user in gen_dict.iteritems():
>     user_dict[item_name[:-3]].add(user) # Sure you want -3 not -5?
>     count_dict[item_name[:-3]] = count_dict.get(item_name[:-3], 0) + 1
> for name, num in sorted(count_dict.iteritems()):
>     print "Version Name : {0}\nNo. of Versions : {1}\nUsers : {2}".format(
>                    name, num, ', '.join(item for item in user_dict[name]))
>
>
> what can I do to input that and any other ways to refine my code?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/401522d4-a96a-4063-9755-863a93de490c%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/401522d4-a96a-4063-9755-863a93de490c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3%2B_VOKUdDKW6FjJQFzgwa22RzNMZCMEVmx6zhoZTZcvw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to