[python-uk] Help Please

Tim Diggins subscribed at red56.co.uk
Thu Feb 1 11:32:18 CET 2007


 > How do I go from here to creating an incidence list representation and
 > adjacency matrix? (is it possible to assign to individual items in 
each tuple? I guess not).

You're right python tuples are immutable (1,2,3), whereas python lists 
[1,2,3] are mutable. However which you use is really a matter of what 
fits your development purposes - NOT what fits your mathematical model - 
mathematically speaking they can both represent a (mathematical) 
tuple... Worthwhile checking out list comprehension syntax [1] as well - 
very expressive syntax (and usually, as added value, the fastest option)

But in general I can't help but think, if you're actually learning 
python, rather than trying to get a quick computational answer to your 
problem, then you'll be better served by making a class to represent 
your underlying objects (and/or as others have suggested using 
appropriate libraries like numpy).

[1] http://docs.python.org/tut/node7.html#SECTION007140000000000000000


Python Freak wrote:
> Okay I finally got the adjancency list representation working:
>  
>    v = range(1,11)
>    al=zip(v[:-1],v[1:])+[(10,)]
>  
> Is that right? It works fine.
>  
>  
> [ for those of you who missed my earlier email, this is not a homework; 
> i'm a graduate student attempting to learn python ].
> 
>  
> On 1/28/07, *Zeth Green* <theology at gmail.com 
> <mailto:theology at gmail.com>> wrote:
> 
>     On 29/01/07, Michael Sparks <ms at cerenity.org
>     <mailto:ms at cerenity.org>> wrote:
>      > Is this homework?
> 
>     I was about to respond with a literal answer but I thought that too.
>     It was the mathematical terminology but especially this bit that made
>     me suspect:
> 
>      > On Sunday 28 January 2007 22:45, Python Freak wrote:
>     Hint: You may find it useful to note that one incidence list
>     representation is...
>     _______________________________________________
>     python-uk mailing list
>     python-uk at python.org <mailto:python-uk at python.org>
>     http://mail.python.org/mailman/listinfo/python-uk
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> python-uk mailing list
> python-uk at python.org
> http://mail.python.org/mailman/listinfo/python-uk



More information about the python-uk mailing list