Article View: alt.privacy.anon-server
Article #201267Re: Python Question
From: Borked Pseudo Mailed
Date: Sat, 28 Jan 2006 06:52
Date: Sat, 28 Jan 2006 06:52
46 lines
2496 bytes
2496 bytes
Anonymous wrote:
> Suppose this:
>
> a = 'aaaa,bbbb,cccc'
> b = a.split(,)
^
Broken. You left out some quotes.
> So:
> b[0] = aaaa
> b[1] = bbbb
> b[2] = cccc
>
> But how can I tell that b[2] is the last element?
>
> if I try to look at b[3], maybe to test if it is a null, the interpreter
> comes back with an error and stops the execution.
Yeah, an "out of range" error just like your Pan script does when it
screws up on certain input, Eelbash.
The solution is elementary because the question is ridiculously basic.
It's not even a Python question really. I'd bet "how do I find the length
of an array" is something every first week programmer in any language
asks, and figuring it out is something any teacher might use as a
tool to teach basic, beginner programming methodologies. You shouldn't be
releasing code to unsuspecting users if you aren't already familiar with
this insanely simple bit of coding. Seriously... all BS aside. Take some
time to learn at least the basics.
And before you start ranting and raving about how I don't know an answer
but just want to pick on someone, two different ways leaped to mind
automatically... indexing and slicing. I'll leave it to you to toil over
why they're different, and which one you might need.
>>> import string
>>> a = 'aaa,bbb,ccc'
>>> b = a.split(',')
>>> b[len(b)-1]
'ccc'
>>> b[-1:]
['ccc']
Technical Details
Message-ID:
<1cfb938c5aff4897a5795a777ff15519@pseudo.borked.net>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!news.glorb.com!news.amigo.co.uk!remailer.org.uk!mail2newsReferences:
<PR3MNVZC38744.7423032407@anonymous>Show Full Headers
Complete Article Headers
Message-ID: <1cfb938c5aff4897a5795a777ff15519@pseudo.borked.net> Subject: Re: Python Question Date: Sat, 28 Jan 2006 06:52:13 +0000 From: Borked Pseudo Mailed <nobody@pseudo.borked.net> References: <PR3MNVZC38744.7423032407@anonymous> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed-east.nntpserver.com!nntpserver.com!statler.nntpserver.com!news.glorb.com!news.amigo.co.uk!remailer.org.uk!mail2news Comments: This message did not originate from the Sender address above. It was remailed automatically by anonymizing remailer software. Please report problems or inappropriate use to the remailer administrator at <admin@pseudo.borked.net>. NNTP-Posting-Host: 71.33.249.113 NNTP-Posting-Host2: 71.33.249.113 X-pugleaf-debug: badGroups=1 valid=1 Newsgroups: alt.privacy.anon-server