On Wed, Oct 24, 2018 at 11:46 AM likage <dissidia....@gmail.com> wrote:

> I have 2 questions, should have done more testing on my end..
>
> 1. I am trying to understand the use of `.append'. I know that it adds
> things to list, but when I was looking thru the documentation page -
> https://docs.python.org/2/library/collections.html, even in the example,
> it is mostly `dict_name['key name'].append(value)` but nowhere near the
> method you have used.. Am I looking at the wrong doc?
>

It isn't actually part of the collections.defaultdict class. You have
constructed:

    dict_name = defaultdict(list)

 That means when you do

    dict_name['key name']

you get a list returned to you. Because python treats everything as first
class objects, you can assign the list.append function to a variable

    aList = dict_name['key name']
    append = aList.append

And its actually a documented performance note:
https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avoiding_dots...


>
> 2. For Method #2 you have proposed, instead of using a defaultdict(list),
> I used a normal dictionary {} and I got the KeyError message.
> Is this because when using normal dictionary, generally it should be
> `dict_name['key name'] = value`, and since we are not doing this way and
> hence the error?
>

I don't recall proposing that you stop using defaultdict. My example
expected that it would be a defaultdict.


>
> Pardon the noob questions as I am trying to make sense of things
>
> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/3a7ad9d5-118b-4617-9806-e5189992b15d%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/3a7ad9d5-118b-4617-9806-e5189992b15d%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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0O_uCsJ01c3yd8N%3DtQG8SBv2T5tjNUXj0Vf-O_DkAYjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to