On Tue, Nov 10, 2015 at 9:59 PM <[email protected]> wrote: > aah ok thanks Justin, i don't quite understand why they would be classed > as None values because they are integers right? or maybe they don't have a > type when mapped. >
map() is a functional programming construct, meant apply the given function to each item in a sequence, and return the results. Example of realistic usage: nums = range(5)print nums# [0,1,2,3,4] doubled = map(lambda i: i*2, nums)print doubled# [0,2,4,6,8] As you can see, you start with a list of numbers, and apply a function that multiplies the value by 2. map() then gives you back a new list, with the mapped values. But look at what happens when you use it for side effects, on something like list.append(), which adds an element to a list but has no return value: aList = [] results = map(aList.append, [1,2,3,4,5])print aList# [1, 2, 3, 4, 5]print results# [None, None, None, None, None] So you see, that while you have managed to append each value to your original list, map() generate a result for you anyways. It is a list of return values from each call to append(). That is just a big list of None values. If you were to do a map() on, say, 10k items, you generate a garbage list of 10k None values, just so you can have the side effect of whatever your function does. Better to just loop and append, in this case. > > but yes this is working nicely, thank you > > Sam > > -- > 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/5d6d8668-c042-4fb6-b35c-91edf6426130%40googlegroups.com > . > 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/CAPGFgA18yVBpAR%2BG4RvhZNcnNqiKyG4UQbTVP0M33bneZd9ZmQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
