[Tutor] Better way to remove lines from a list?
Peter Otten
__peter__ at web.de
Wed May 13 15:41:06 EDT 2020
boB Stepp wrote:
> On Wed, May 13, 2020 at 08:04:10PM +0200, Peter Otten wrote:
>>boB Stepp wrote:
>>
>>> On Tue, May 12, 2020 at 11:59:18PM +0200, Peter Otten wrote:
>
>>>># assuming that the colon after one of your ADRs is a typo
>>>
>>> That eighth semicolon is no typo. That is a direct copy and paste from
>>> a Google contacts export in vCard format.
>
> Oops! I did read your "colon" as semicolon. But despite that...
>
>>>>> ADR:100;;4700 E McCain Blvd;North Little Rock;AR;72117;US;4700 E
>>>>> McCain
>>
>>I meant the ":" after "ADR" in the line above, not the ";" after US in
>
> That is still legitimate syntax (with the colon after ADR). The "TYPE="
> is
> entirely optional. I notice that the lack of "TYPE=" shows up in my
> Google contacts export whenever the type set in Google Contacts is
> "Other".
>
Then my suggested startswith check
def cleaned(line):
if line.startswith("ADR;"):
line = ";".join(line.split(";")[:8])
return line + "\n"
is wrong. I felt a little uneasy with just
line.startswith("ADR")
because in theory more letters could follow.
More information about the Tutor
mailing list