Cleaning up conditionals

Deborah Swanson python at deborahswanson.net
Fri Dec 30 19:26:43 EST 2016


> On 31 December 2016 at 10:00, Deborah Swanson 
> <python at deborahswanson.net> wrote:
> >
> > Oops, indentation was messed up when I copied it into the email.
> 
> The indentation of your latest message looks completely 
> broken  now, you can see it here: 
> https://mail.python.org/pipermail/python-list/2016-December/71
7758.html

Hm, I don't know what pipermail does with whitespace but the formatting
in the message at
https://mail.python.org/pipermail/python-list/2016-December/717758.html
is not the same as the message I sent from Outlook.

Again, it should have been:

if len(l1[st]) == 0:
	if len(l2[st]) > 0:
		l1[st] = l2[st]
elif len(l2[st]) == 0:
	if len(l1[st]) > 0:
		l2[st] = l1[st]

(Maybe keeping the left edge flush with the left margin will help keep
the mail processors straight. I've never tried emailing python code
before.)

As Mr. Bieber points out, what I had above greatly benefits from the use
of conjunctions. It now reads:

if not len(l1[st]) and len(l2[st]):
		l1[st] = l2[st]
elif not len(l2[st]) and len(l1[st]):
		l2[st] = l1[st]

(I plead being cross-eyed from rewriting this section so many times for
not seeing this.)

I'm still wondering if these 4 lines can be collapsed to one or two
lines.




More information about the Python-list mailing list