"Deborah Swanson" writes:
> I'm still wondering if these 4 lines can be collapsed to one or two
> lines.
In the trade that's what we call a "code smell", a sign that code (even if it
works) should probably be re-thought after taking a step back to understand
what it is really trying to do.
Wha
"Deborah Swanson" writes:
> I'm still wondering if these 4 lines can be collapsed to one or two
> lines.
In the trade that's what we call a "code smell", a sign that code
(even if it works) should probably be re-thought after taking a step
back to understand what it is really trying to do.
What
On Tue, Jan 3, 2017 at 8:18 PM, Deborah Swanson
wrote:
> OrderedDict is the new development I'd read about, but I think the key
> order is just the order keys were added to the dict. The nice thing
> about that though is when you loop over a dict you will always get the
> key/value pairs in the sa
Chris Angelico wrote, on January 03, 2017 12:14 AM
>
> On Tue, Jan 3, 2017 at 6:35 PM, Deborah Swanson
> wrote:
> > I think I'm right that core python sequences can't be
> indexed in any
> > fashion by strings, because strings aren't iterable. I suppose it
> > might be possible for strings to
On Tue, Jan 3, 2017 at 6:35 PM, Deborah Swanson
wrote:
> I think I'm right that core python sequences can't be indexed in any
> fashion by strings, because strings aren't iterable. I suppose it might
> be possible for strings to be iterable in some sort of ascii char code
> order, but that seems l
Gregory Ewing wrote, on January 02, 2017 7:58 PM
>
> Deborah Swanson wrote:
> > Unless you know of, and are suggesting, a way to index a
> sequence with
> > strings instead of integers, so the code could remain
> untouched with
> > string indices when changes to the columns are made.
>
> I'm
Deborah Swanson wrote:
Unless you know of, and are suggesting, a way to index a sequence with
strings instead of integers, so the code could remain untouched with
string indices when changes to the columns are made.
I'm talking about this:
https://docs.python.org/3/library/collections.html#col
Gregory Ewing wrote, on Monday, January 02, 2017 3:28 PM
>
> Deborah Swanson wrote:
> > flds = len(ls[0])
> > cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar =
> > range(0,flds)
>
> You might like to consider converting the row into a
> namedtuple, then you could refer to the fields u
Deborah Swanson wrote:
flds = len(ls[0])
cl, ur, d1, de, lo, st, mi, ki, re, da, br, no, yn, ma, ar =
range(0,flds)
You might like to consider converting the row into a
namedtuple, then you could refer to the fields using
attribute names instead of indexes.
You could even use the header row to
Dennis Lee Bieber wrote on January 02, 2017 8:30 AM
>
> On Sun, 1 Jan 2017 18:30:03 -0800, "Deborah Swanson"
> declaimed the following:
>
> Out of curiosity -- don't those listings have street
> addresses? There must be lots of "2 br" units in the city.
>
> Part of the hassle
Dennis Lee Bieber wrote, on January 02, 2017 8:30 AM:
>
> On Sun, 1 Jan 2017 18:30:03 -0800, "Deborah Swanson"
> declaimed the following:
>
> >Dennis Lee Bieber wrote, on Sunday, January 01, 2017 6:07 PM
> >>
> >>
> >> l1 2 br, Elk Plains12-26 WA/pi
> >> l2 2 br, Elk Plains
Op 31-12-16 om 01:26 schreef Deborah Swanson:
>> On 31 December 2016 at 10:00, Deborah Swanson
>> 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.or
Jussi Piitulainen wrote, on January 02, 2017 1:44 AM
>
> Deborah Swanson writes:
> > Jussi Piitulainen wrote:
>
> [snip]
>
> >> With your particular conditions of non-emptiness, which is
> taken to
> >> be truth, you can achieve variations of this result with
> any of the
> >> following stat
Deborah Swanson writes:
> Jussi Piitulainen wrote:
[snip]
>> With your particular conditions of non-emptiness, which is taken to
>> be truth, you can achieve variations of this result with any of the
>> following statements:
>>
>> w = ( l1[v] if len(l1[v]) > 0 else
>> l2[v] if len(l2[v]) >
Dennis Lee Bieber wrote, on Sunday, January 01, 2017 6:07 PM
>
> On Sun, 1 Jan 2017 15:50:25 -0800, "Deborah Swanson"
> declaimed the following:
>
> >Maybe it would help if I give a couple rows of (made up)
> data to show
> >what I mean (first row is field titles):
> >
> >..Description
On 01/01/2017 14:32, Rustom Mody wrote:
On Sunday, January 1, 2017 at 7:51:12 PM UTC+5:30, Rustom Mody wrote:
On Sunday, January 1, 2017 at 3:39:14 PM UTC+5:30, Deborah Swanson wrote:
Sorry guys. I've read all your responses and I kind of get their general
drift, but I'm about four sheets to th
On Sat, 31 Dec 2016 14:35:46 -0800, "Deborah Swanson"
declaimed the following:
if len(l1[v]) == 0 and len(l2[v]) != 0:
l1[v] = l2[v]
elif len(l2[v]) == 0 and len(l1[v]) != 0:
l2[v] = l1[v]
elif l1[v] != l2[v]:
ret += ", " + labels[v] + " diff" if
> -Original Message-
> From: Python-list
> [mailto:python-list-bounces+python=deborahswanson.net@python.o
> rg] On Behalf Of Jussi Piitulainen
> Sent: Saturday, December 31, 2016 11:45 PM
> To: python-list@python.org
> Subject: Re: Cleaning up conditiona
Chris Angelico wrote on Saturday, December 31, 2016 9:39 PM
>
> On Sun, Jan 1, 2017 at 2:58 PM, Deborah Swanson
> wrote:
> > I'm not sure I understand what you did here, at least not
> well enough
> > to try it.
> >
> > What conditional can I do between the 2 rows of listings (the list
> > na
Steve D'Aprano wrote
> Sent: Saturday, December 31, 2016 10:25 PM
>
> On Sun, 1 Jan 2017 02:58 pm, Deborah Swanson wrote:
>
> >> It's possible to select either l1 or l2 using an
> expression, and then
> >> subscript that with [v]. However, this does not usually make for
> >> readable code, so
On Sunday, January 1, 2017 at 7:51:12 PM UTC+5:30, Rustom Mody wrote:
> On Sunday, January 1, 2017 at 3:39:14 PM UTC+5:30, Deborah Swanson wrote:
> > Sorry guys. I've read all your responses and I kind of get their general
> > drift, but I'm about four sheets to the wind right now, and no way would
On Sunday, January 1, 2017 at 3:39:14 PM UTC+5:30, Deborah Swanson wrote:
> Sorry guys. I've read all your responses and I kind of get their general
> drift, but I'm about four sheets to the wind right now, and no way would
> I make it more than a step or two in playing around with these things
> a
Sorry guys. I've read all your responses and I kind of get their general
drift, but I'm about four sheets to the wind right now, and no way would
I make it more than a step or two in playing around with these things
and trying to get my head around them before it would all descend into a
cacaphony
Steve D'Aprano writes:
> On Sun, 1 Jan 2017 02:58 pm, Deborah Swanson wrote:
>
>>> It's possible to select either l1 or l2 using an expression,
>>> and then subscript that with [v]. However, this does not
>>> usually make for readable code, so I don't recommend it.
>>>
>>> (l1 if whatever else l2
Deborah Swanson writes:
> Jussi Piitulainen wrote:
>> Sent: Saturday, December 31, 2016 8:30 AM
>> Deborah Swanson writes:
>>
>> > Is it possible to use some version of the "a = expression1 if
>> > condition else expression2" syntax with an elif? And for
>> > expression1 and expression2 to be sin
On Sun, 1 Jan 2017 02:58 pm, Deborah Swanson wrote:
>> It's possible to select either l1 or l2 using an expression,
>> and then subscript that with [v]. However, this does not
>> usually make for readable code, so I don't recommend it.
>>
>> (l1 if whatever else l2)[v] = new_value
>>
>> ChrisA
>
On Sun, Jan 1, 2017 at 2:58 PM, Deborah Swanson
wrote:
> I'm not sure I understand what you did here, at least not well enough to
> try it.
>
> What conditional can I do between the 2 rows of listings (the list names
> l1 and l2) that will give me which row has the value to copy from and
> which o
Dennis Lee Bieber
> Sent: Saturday, December 31, 2016 7:29 PM
>
> On Sat, 31 Dec 2016 14:35:46 -0800, "Deborah Swanson"
> declaimed the following:
>
> >Here's the function I have so far:
> >
> >def comprows(l1,l2,st,ki,no):
> >ret = ''
> >labels = {st: 'st/co', ki: 'kind', no: 'notes'}
Chris Angelico wrote:
> Sent: Saturday, December 31, 2016 2:19 PM
>
> On Sun, Jan 1, 2017 at 9:03 AM, Deborah Swanson
> wrote:
> > And didn't finish it because I couldn't see what a should
> be. I want
> > it to be l2[v] if the first clause is true, and l1[v] if
> the second.
> > If I was co
Deborah Swanson wrote:
> Peter Otten wrote:
>> Deborah Swanson wrote:
>>
>> > Here I have a real mess, in my opinion:
>>
>> [corrected code:]
>>
>> > if len(l1[st]) == 0:
>> > if len(l2[st]) > 0:
>> > l1[st] = l2[st]
>> > elif len(l2[st]) == 0:
>> >
On 2016-12-31 22:35, Deborah Swanson wrote:
Peter Otten wrote:
Deborah Swanson wrote:
> Here I have a real mess, in my opinion:
[corrected code:]
> if len(l1[st]) == 0:
> if len(l2[st]) > 0:
> l1[st] = l2[st]
> elif len(l2[st]) == 0:
> i
Peter Otten wrote:
> Deborah Swanson wrote:
>
> > Here I have a real mess, in my opinion:
>
> [corrected code:]
>
> > if len(l1[st]) == 0:
> > if len(l2[st]) > 0:
> > l1[st] = l2[st]
> > elif len(l2[st]) == 0:
> > if len(l1[st]) > 0:
> >
On Sun, Jan 1, 2017 at 9:03 AM, Deborah Swanson
wrote:
> And didn't finish it because I couldn't see what a should be. I want it
> to be
> l2[v] if the first clause is true, and l1[v] if the second. If I was
> computing a value, this would work beautifully, but I don't see how it
> can if I'm choo
Jussi Piitulainen wrote:
> Sent: Saturday, December 31, 2016 8:30 AM
> Deborah Swanson writes:
>
> > Is it possible to use some version of the "a = expression1 if
> > condition else expression2" syntax with an elif? And for
> expression1
> > and expression2 to be single statements? That's the
On 2016-12-30 19:59, Deborah Swanson wrote:
> Similar, actually the same as Cameron suggested. I really need to
> revisit testing for empty. I probably rejected it early on for some
> bad reason (you don't understand everything that goes wrong when
> you're learning).
If your data is anything like
> From: Tim Chase
> Sent: Saturday, December 31, 2016 12:41 PM
> On 2016-12-30 19:59, Deborah Swanson wrote:
> > Similar, actually the same as Cameron suggested. I really need to
> > revisit testing for empty. I probably rejected it early on for some
> > bad reason (you don't understand everythin
Jussi Piitulainen wrote:
> Sent: Saturday, December 31, 2016 8:30 AM
> Deborah Swanson writes:
>
> > Is it possible to use some version of the "a = expression1 if
> > condition else expression2" syntax with an elif? And for
> expression1
> > and expression2 to be single statements? That's the
Deborah Swanson writes:
> Is it possible to use some version of the "a = expression1 if
> condition else expression2" syntax with an elif? And for expression1
> and expression2 to be single statements? That's the kind of
> shortcutting I'd like to do, and it seems like python might be able to
> d
Deborah Swanson wrote:
> Here I have a real mess, in my opinion:
[corrected code:]
> 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]
> Anybody kn
On Sat, 31 Dec 2016 11:26 am, Deborah Swanson wrote:
> 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]
Your code c
"Deborah Swanson" writes:
> Michael Torrie wrote:
>> On 12/30/2016 05:26 PM, Deborah Swanson wrote:
>> > I'm still wondering if these 4 lines can be collapsed to one or two
>> > lines.
>>
>> If the logic is clearly expressed in the if blocks that you
>> have, I don't see why collapsing an if b
Michael Torrie wrote:
> On 12/30/2016 05:26 PM, Deborah Swanson wrote:
> > I'm still wondering if these 4 lines can be collapsed to one or two
> > lines.
>
> If the logic is clearly expressed in the if blocks that you
> have, I don't see why collapsing an if block into one or two
> lines would
> On 2016-12-31 00:48, Deborah Swanson wrote:
> >> On 30/12/16 23:00, Deborah Swanson wrote:
> >> > Oops, indentation was messed up when I copied it into the email.
> >> > Should be this:
> >> >
> >> > if len(l1[st]) == 0:
> >> > if len(l2[st]) > 0:
> >> >
> On 30Dec2016 15:17, Deborah Swanson wrote:
> >>Ever consider using conjunctions?
> >>
> >>if len(l1[st]) and not len(l2[st]):
> >>#0 is considered a false -- no need to test for "==0"
> >>#non-0 is considered true -- no need to test for ">0"
> >>#copy
On 2016-12-31 01:59, Cameron Simpson wrote:
On 30Dec2016 15:17, Deborah Swanson wrote:
Ever consider using conjunctions?
if len(l1[st]) and not len(l2[st]):
#0 is considered a false -- no need to test for "==0"
#non-0 is considered true -- no nee
On 30Dec2016 15:17, Deborah Swanson wrote:
Ever consider using conjunctions?
if len(l1[st]) and not len(l2[st]):
#0 is considered a false -- no need to test for "==0"
#non-0 is considered true -- no need to test for ">0"
#copy l1 t
On 2016-12-31 00:48, Deborah Swanson wrote:
On 30/12/16 23:00, Deborah Swanson wrote:
> Oops, indentation was messed up when I copied it into the email.
> Should be this:
>
>if len(l1[st]) == 0:
> if len(l2[st]) > 0:
> l1[st] = l2[st]
>
On 12/30/2016 05:26 PM, Deborah Swanson wrote:
> I'm still wondering if these 4 lines can be collapsed to one or two
> lines.
If the logic is clearly expressed in the if blocks that you have, I
don't see why collapsing an if block into one or two lines would even be
desirable. Making a clever one
> On 31/12/16 00:26, Deborah Swanson wrote:
> > 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]):
>
> IMHO, "if not len(l)" is a _terrible_ way of spelling "if
> len(l) == 0"
> (mentally, I
> On 30/12/16 23:00, Deborah Swanson wrote:
> > Oops, indentation was messed up when I copied it into the email.
> > Should be this:
> >
> > if len(l1[st]) == 0:
> > if len(l2[st]) > 0:
> > l1[st] = l2[st]
> > elif len(l2[st]) == 0:
> >
On 31/12/16 00:26, Deborah Swanson wrote:
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]):
IMHO, "if not len(l)" is a _terrible_ way of spelling "if len(l) == 0"
(mentally, I have to read that as "if le
> On 31 December 2016 at 10:00, Deborah Swanson
> 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
775
On 30/12/16 23:00, Deborah Swanson wrote:
Oops, indentation was messed up when I copied it into the email. Should
be this:
if len(l1[st]) == 0:
if len(l2[st]) > 0:
l1[st] = l2[st]
elif len(l2[st]) == 0:
if len(l1[st]
> On Fri, 30 Dec 2016 13:20:15 -0800, "Deborah Swanson"
> declaimed the following:
>
> >I've already learned one neat trick to collapse a conditional:
> >
> > a = expression1 if condition else expression2
> >
> >Here I have a real mess, in my opinion:
> >
> > if len(l1[st]) == 0:
> >
On 31 December 2016 at 10:00, Deborah Swanson 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/717758.html
--
https://m
BartC wrote:
> Sent: Friday, December 30, 2016 2:11 PM
>
> On 30/12/2016 21:20, Deborah Swanson wrote:
> > I've already learned one neat trick to collapse a conditional:
> >
> > a = expression1 if condition else expression2
> >
> > Here I have a real mess, in my opinion:
> >
> > if len(l1[
On 30/12/2016 21:20, Deborah Swanson wrote:
I've already learned one neat trick to collapse a conditional:
a = expression1 if condition else expression2
Here I have a real mess, in my opinion:
if len(l1[st]) == 0:
if len(l2[st]) > 0:
l1[st] = l2[st]
57 matches
Mail list logo