Re: Initializing a set from a list
Robert Kern wrote: > Xiaolei Li wrote: > > Hi, > > > > I'm trying to initialize a set from a list but am unable to do so. My > > list "c", looks like: > > > > [(1.00909, 0.91966, -0.13550388182991072, 0), > > (0.874239991, 0.7001, -0.2123048713754, 0)] > > > > So basically a list of 2 tuples, each with 4 elements. Since tuples > > are immutable, I think a set should be able to support them. > > > > Anyway, I then do: > > > > set_c = set(c) > > > > And instead of getting a set, I get "None" when I try to print out > > set_c. len(set_c) complains "TypeError: len() of unsized object." > > Help? > > >>> c = [(1.00909, 0.91966, -0.13550388182991072, 0), > ... (0.874239991, 0.7001, -0.2123048713754, 0)] > >>> set_c = set(c) > >>> set_c > set([(1.00909, 0.91966, -0.13550388182991072, 0), > (0.874239991, 0.7001, -0.2123048713754, 0)]) > >>> > > Please copy-and-paste the exact code that you wrote and the exact output. Ok, I've basically found the cause of my problem. I'm including stuff from pylab and that's causing some conflicts? Here's 6 lines of code: from pylab import * c = [1, 2, 3, 3] print c set_c = set(c) print set print set_c When I run that (Python 2.4.2, Pylab 0.80), I get: [1, 2, 3, 3] None If I remove the first line, I correctly get: [1, 2, 3, 3] set([1, 2, 3]) Good news is that I didn't really need pylab in the program. So for now, everything's working just fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Initializing a set from a list
Sybren Stuvel wrote: > Xiaolei enlightened us with: > > from pylab import * > > You'd better not do that. Just use "import pylab". > > > If I remove the first line, I correctly get: > > > > [1, 2, 3, 3] > > > > set([1, 2, 3]) > > Pylab shadows the built-in set name, which is one of the reasons you > should generally use "import XXX" instead of "from XXX import *". Ahh. Understood. Thank you very much. -- http://mail.python.org/mailman/listinfo/python-list
Auto color selection PIL
Hi, I'm trying to plot some points in an image. Each point has an associating type and I'd like to have different colors (preferrably of high contrast) for different types. The number of types in the data file is unknown a priori. Is there a way to do this at runtime? The "solution" I have so far has been to manually create a list of 10-20 contrasting colors and just go off that list at runtime. This works most of the time since the number of types is usually less than 10. But I'd like a general solution. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Initializing a set from a list
Hi, I'm trying to initialize a set from a list but am unable to do so. My list "c", looks like: [(1.00909, 0.91966, -0.13550388182991072, 0), (0.874239991, 0.7001, -0.2123048713754, 0)] So basically a list of 2 tuples, each with 4 elements. Since tuples are immutable, I think a set should be able to support them. Anyway, I then do: set_c = set(c) And instead of getting a set, I get "None" when I try to print out set_c. len(set_c) complains "TypeError: len() of unsized object." Help? Thank you. -- http://mail.python.org/mailman/listinfo/python-list