The Zen of Python is readability? Does this look neater? x11, y11, x12, y12, x21, y21, x22, y22 = line1[0] + line1[1] + line2[0] + line2[1]
Compared to tuples, lists are maybe more useful if you need to manipulate the coordinates. line1 = [ [1, 2], [3, 4] ] line1[1][0] = 5 line1[0] = [2, 3] or _p1, _p2, _x, _y = 0, 1, 0, 1 line1 = [ [1, 2], [3, 4] ] line1[_p2][_x] = 5 line1[_p1] = [2, 3] On Wed, Aug 21, 2019 at 5:15 AM Michael F. Stemper < michael.stem...@gmail.com> wrote: > I recently wrote a couple of modules (more to come) to help me > use the tikz package in TeX/LaTeX. Since it's all to do with > drawing, I have a lot of points in R^2. Being unimaginative, I > implemented them as ordered pairs (2-tuples) of floats. E.g.: > > p1 = 3,4 > p2 = 5,6 > > Naturally, lines are implemented as ordered pairs[1] of points: > > line = p1,p2 > > This all seems reasonably simple and intuitive (to me). However, > in order to actually do some manipulation, I have stuff like: > > # Unpack the lines > l1p1,l1p2 = line1 > l1x1,l1y1 = l1p1 > l1x2,l1y2 = l1p2 > l2p1,l2p2 = line2 > l2x1,l2y1 = l2p1 > l2x2,l2y2 = l2p2 > > spattered all over. Although this is simple enough, I find it > aesthetically unappealing. > > Is there some better idiom that I should be using, or is this > really in accord with The Zen of Python? > > [1] (I could have done sets, I suppose, but orientation might be > useful at some point.) > > -- > Michael F. Stemper > The FAQ for rec.arts.sf.written is at: > http://leepers.us/evelyn/faqs/sf-written > Please read it before posting. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list