Re: [Tutor] Recommendation For A Complete Noob
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 12/02/14 00:58, Dave Angel wrote: > Bob Williams Wrote in message: > > >> to slice those lines to get the artist and album names into a >> list. >> >> So far, so good but my output contains duplicates, so my final >> task is to work out how to get rid of them. >> > > > Hint: a set will contain only one of each item. So if you have a > list of immutable items, the following will eliminate duplicates: > > newlist = list (set (oldlist)) > > Sometimes a dict is better, if only part of each item is to be > made unique. > > This assumes that order doesn't matter. If it does, perhaps an > ordered dict. > Many thanks, Dave. That worked perfectly. Ordering doesn't matter in this case, but I might try it as an exercise. Bob - -- Bob Williams System: Linux 3.11.10-7-desktop Distro: openSUSE 13.1 (x86_64) with KDE Development Platform: 4.12.2 Uptime: 06:00am up 2 days 10:01, 5 users, load average: 0.35, 0.31, 0.21 -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.22 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iEYEARECAAYFAlL7QxsACgkQ0Sr7eZJrmU6I+gCffgK34BBSBPQ02ZjAKm/TwlUQ VyoAn1etNjuywwWIa1e2fqx9YlGeXGu9 =NhPX -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better flow for this?
On 02/12/2014 03:06 AM, R. Alan Monroe wrote: I started on an implementation of a solitaire board game simulating a B52 bombing run ( http://victorypointgames.com/details.php?prodId=119 ). It seems like there ought to be a better way to structure this program flow, but it's escaping me at the moment. (pseudo code) Also explain the logic in plain words. Else, we can only guess. d ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better flow for this?
On 02/12/2014 10:51 AM, spir wrote: On 02/12/2014 03:06 AM, R. Alan Monroe wrote: I started on an implementation of a solitaire board game simulating a B52 bombing run ( http://victorypointgames.com/details.php?prodId=119 ). It seems like there ought to be a better way to structure this program flow, but it's escaping me at the moment. (pseudo code) Also explain the logic in plain words. Else, we can only guess. d This will also help you and check the design. d ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recommendation For A Complete Noob
On Tue, 2014-02-11 at 23:25 +, Bob Williams wrote: […] > I'm also a noob. In addition to all the excellent recommendations > already posted, I would suggest setting yourself a task to solve in > python. It's far more interesting than working through the examples in > most books - the challenge is solving each problem as you come across > them. Google is excellent. Definitely. What you also need is to get feedback on your code from another person. Knowing whether your solution is good, Pythonic, or needs more work, is separate from does it pass its tests and does it do what it should. -- Russel. = Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.win...@ekiga.net 41 Buckmaster Roadm: +44 7770 465 077 xmpp: rus...@winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better flow for this?
> Also explain the logic in plain words. Else, we can only guess. Were the comments not enough? You keep taking turns until you get home or die. Each turn has 4 phases. while playing: #phase 1 - fly every turn, you might die #phase 2 - stuff shoots at you every turn, you might die #phase 3 - may or may not get an event card, with certain cards you might die #phase 4 - you drop bombs if you're over a target, you can't die here game over, print score Alan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recommendation For A Complete Noob
> Hi, > > I'm completely new to programming in general and everything I have read so > far has pointed me to Python. I was just hoping to get some input as to where > I might start. > Start with Python programming for the absolute beginner Great author. The book gives you lots of exercises at the end of each chapter to make sure you understood everything up to that point. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Better flow for this?
> You keep taking turns until you get home or die. Each turn has 4 > phases. > while playing: > #phase 1 - fly every turn, you might die > #phase 2 - stuff shoots at you every turn, you might die > #phase 3 - may or may not get an event card, with certain cards you might > die > #phase 4 - you drop bombs if you're over a target, you can't die here > game over, print score Thinking about this this morning, I struck upon this idea, which seems much cleaner: -- def phase1(): #do stuff return boolSurvived def phase2(): #do stuff return boolSurvived def phase2(): #do stuff return boolSurvived def phase4(): #do stuff while playing: #phase 1 - fly every turn, you might die playing = phase1() #phase 2 - stuff shoots at you every turn, you might die if playing: playing=phase2() #phase 3 - may or may not get an event card, with certain cards you might die if playing: playing=phase3() #phase 4 - you drop bombs if you're over a target, you can't die here if playing: phase4() game over, print score -- Alan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Beginner - explaining 'Flip a coin' bug
Hello there, I want to emulate a coin flip and count how many heads and tails when flipping it a hundred times. I first coded coinflip_WRONG.py with "count_flips += 1" statement within the if/else block. When running it, either returned values are wrong or the script seems to enter in an infinite loop showing no return values at all. coinflip.py is a corrected version I worked out myself. I moved "count_flips+= 1" out of if/else block and inserted it before if/else. However, I still don't understand the bug since, in my understanding, both files are incrementing variable count_flips each time until the loop becomes false. Can somebody explain the reason of the bug. Cheers, Marc #Coin Flip #Flip a coin 100 times and count heads and tails input('Press ENTER to flip a coin a hundred times') import random #set count values count_heads = 0 count_tails = 0 count_flips = 0 while count_flips != 100: coin_side = random.randint(1,2) count_flips += 1 if coin_side == 1: count_heads += 1 #count_flips += 1 else: count_tails += 1 #count_flips += 1 print('The coin returned',count_heads,'heads and',count_tails,'tails.') #Coin Flip #Flip a coin 100 times and count heads and tails input('Press ENTER to flip a coin a hundred times') import random #set count values count_heads = 0 count_tails = 0 count_flips = 0 while count_flips != 100: coin_side = random.randint(1,2) #count_flips += 1 if coin_side == 1: count_heads += 1 count_flips += 1 else: count_tails += 1 count_flips += 1 print('The coin returned',count_heads,'heads and',count_tails,'tails.') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
> Can somebody explain the reason of the bug. I think you have an indentation goof on line 24 in the "wrong" version (the else clause). Alan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
Marc Eymard Wrote in message: > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > Next time please post in text form rather than html, and actually include the code you're asking us to comment on. -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On 12/02/14 15:25, Marc Eymard wrote: However, I still don't understand the bug since, in my understanding, both files are incrementing variable *count_flips* each time until the loop becomes false. > count_heads = 0 > count_tails = 0 > count_flips = 0 > > while count_flips != 100: This is usually a bad idea since if count_flips gets incremented by 2 it could go over 100 and this test will still be true and it will loop forever... (see below). Its better to have a test like: while count_flips <100: >coin_side = random.randint(1,2) > >if coin_side == 1: >count_heads += 1 >count_flips += 1 >else: count_tails += 1 > >count_flips += 1 Because this is outside the else block it gets incremented twice every time a 1 gets 'thrown'. (see above) That's why your solution of incrementing only once before the if/else tests is better. Its a more accurate implementation of the logic and avoids the double increment problem with the while loop. HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
Hi Marc, On Wed, Feb 12, 2014 at 9:25 AM, Marc Eymard wrote: > Hello there, > > I want to emulate a coin flip and count how many heads and tails when > flipping it a hundred times. > > I first coded coinflip_WRONG.py with "count_flips += 1" statement within the > if/else block. > When running it, either returned values are wrong or the script seems to > enter in an infinite loop showing no return values at all. > > coinflip.py is a corrected version I worked out myself. I moved > "count_flips+= 1" out of if/else block and inserted it before if/else. > > However, I still don't understand the bug since, in my understanding, both > files are incrementing variable count_flips each time until the loop becomes > false. > > Can somebody explain the reason of the bug. The problem is that conflip_WRONG.py isn't doing what you think it's doing :). In particular, lines 23 and 24: """ else: count_tails += 1 count_flips += 1 """ While including a statement on the same line after "else:" is legal, it restricts you to only one statement in the block. So if we move that statement off of that line and into the block, we have this: """ else: count_tails += 1 count_flips += 1 """ I think you may be able to see what's going on from here, but to spell it out: instead of being executed in the else block, "count_flips +=1" is being executed unconditionally. Since there's also a "count_flips += 1" in the "if coin_side == 1" block, count_flips is incremented twice when coin_side == 1, and once otherwise. Since your loop condition is "coin_flips != 100", when you reach the point of coin_flips == 99 and coin_side comes up 1, coin_flips will be incremented to 101, and the loop condition will still be satisfied--hence your infinite loop. Having "count_flips += 1" outside the if/else construct is better code, since you want it to be done exactly once each time through the loop no matter what, and reduces repetition. There are several other ways to improve your code as well, but they'll come with experience (or from asking :)). Hope this helps, -- Zach ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 02:08:17PM -0500, Dave Angel wrote: > Marc Eymard Wrote in message: > > ___ > > Tutor maillist - Tutor@python.org > > To unsubscribe or change subscription options: > > https://mail.python.org/mailman/listinfo/tutor > > > Next time please post in text form rather than html, and actually > include the code you're asking us to comment on. Dave, your tools are letting you down. Marc did post in text, and did include his code, as you can see from the multipart attachments to his email: I 1 [multipa/alternativ, 7bit, 2.0K] I 2 ├─> [text/plain, quoted, iso-8859-1, 0.7K] I 3 └─> [text/html, quoted, iso-8859-1, 1.0K] A 4 coinflip.py [text/x-script.p, base64, us-ascii, 0.6K] A 5 coinflip_WRONG.py [text/x-script.p, base64, us-ascii, 0.6K] I 6 [text/plain, 7bit, us-ascii, 0.2K] Perhaps it is time for you to give up on whatever tool you are using to read this mailing list, or at least to change your assumption when you see a contentless message from "Original poster didn't send email" to "I can't see the email". -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
> When running it, either returned values are wrong or the script > seems to enter in an infinite loop showing no return values at all. One other tip: "for" loops are usually more practical when you know exactly how many times you want to loop (100 coin flips). "while" loops are usually more practical when you don't know in advance how many times it might loop. Alan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 03:25:22PM +, Marc Eymard wrote: > However, I still don't understand the bug since, in my understanding, > both files are incrementing variable count_flips each time until the > loop becomes false. The problem with the "wrong" file is that it increments the count_flaps variable too many times. You have code: while count_flips != 100: coin_side = random.randint(1,2) #count_flips += 1 if coin_side == 1: count_heads += 1 count_flips += 1 else: count_tails += 1 count_flips += 1 where I have added the annotations A and B. So you can see that each time you flip Heads, the "if" statement runs the indented block with two lines: if coin_side == 1: count_heads += 1 count_flips += 1 then jumps past the "else" block with a single in-line statement: else: count_tails += 1 and continues running the code past the if...else block, but still inside the while block past: count_flips += 1 So every time you toss a Head, the number of flips is incremented TWICE instead of once. That means that sometimes you'll have fewer than 100 coin tosses, as seen by adding the number of Heads and Tails, e.g. you might have 30 Tails and 35 Heads (each Tail counts once, and each Head counts twice, giving 100 mis-counted flips). But occasionally, if you happen to toss Heads when the count is at 99, you'll jump to 101 skipping over 100, and the while-loop then will loop forever. In my next email, I'll explain how to better improve the code. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 03:25:22PM +, Marc Eymard wrote: > I want to emulate a coin flip and count how many heads and tails when > flipping it a hundred times. In my last reply, I said I'd next give you some pointers to improve the code. If you'd rather work on it yourself first, stop reading now! In your working code, you have (in part): count_heads = 0 count_tails = 0 count_flips = 0 while count_flips != 100: coin_side = random.randint(1,2) count_flips += 1 if coin_side == 1: count_heads += 1 #count_flips += 1 else: count_tails += 1 #count_flips += 1 The first thing to notice is that by the logic of the task, each flip must be either a Head or a Tail, so the number of Heads and the number of Tails should always add up to the number of flips. So you don't need to record all three variables, you only need two of them. The second thing is that since the number of flips is incremented by one every single time through the loop, regardsless of what happens, you don't need to manually increment that. You can get Python to do the counting for you, using a for-loop: for count_flips in range(1, 101): coin_side = random.randint(1,2) if coin_side == 1: count_heads += 1 At the end of the loop, you will have count_flips equal to 100 (can you see why?) and the number of Tails will be count_flips - count_heads. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On 2014-02-12, Steven D'Aprano wrote: > On Wed, Feb 12, 2014 at 02:08:17PM -0500, Dave Angel wrote: >> Next time please post in text form rather than html, and >> actually include the code you're asking us to comment on. > > Dave, your tools are letting you down. Marc did post in text, and did > include his code, as you can see from the multipart attachments to his > email: > > I 1 [multipa/alternativ, 7bit, 2.0K] > I 2 ??> [text/plain, quoted, iso-8859-1, 0.7K] > I 3 ??> [text/html, quoted, iso-8859-1, 1.0K] > A 4 coinflip.py [text/x-script.p, base64, us-ascii, 0.6K] > A 5 coinflip_WRONG.py [text/x-script.p, base64, us-ascii, 0.6K] > I 6 [text/plain, 7bit, us-ascii, 0.2K] > > > Perhaps it is time for you to give up on whatever tool you are > using to read this mailing list, or at least to change your > assumption when you see a contentless message from "Original > poster didn't send email" to "I can't see the email". This is also a USENET newsgroup, where attachements are not a thing. -- Neil Cerutti ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On 02/12/2014 10:14 PM, Steven D'Aprano wrote: On Wed, Feb 12, 2014 at 03:25:22PM +, Marc Eymard wrote: I want to emulate a coin flip and count how many heads and tails when flipping it a hundred times. In my last reply, I said I'd next give you some pointers to improve the code. If you'd rather work on it yourself first, stop reading now! In your working code, you have (in part): count_heads = 0 count_tails = 0 count_flips = 0 while count_flips != 100: coin_side = random.randint(1,2) count_flips += 1 if coin_side == 1: count_heads += 1 #count_flips += 1 else: count_tails += 1 #count_flips += 1 The first thing to notice is that by the logic of the task, each flip must be either a Head or a Tail, so the number of Heads and the number of Tails should always add up to the number of flips. So you don't need to record all three variables, you only need two of them. The second thing is that since the number of flips is incremented by one every single time through the loop, regardsless of what happens, you don't need to manually increment that. You can get Python to do the counting for you, using a for-loop: for count_flips in range(1, 101): coin_side = random.randint(1,2) if coin_side == 1: count_heads += 1 At the end of the loop, you will have count_flips equal to 100 (can you see why?) and the number of Tails will be count_flips - count_heads. Actually, there are 2 distinct points: * That one doesn't need to count flips: right. * That one needs only to count one eveny kind is accidental, just because there are here only 2 event kinds, so that number of tails+heads=flips. In the general case, Marc's solution to count each even kind is just right. [To compare, there are people using bools to represent 2 distinct cases (eg black & white in a chass game), and it's conceptually wrong: white is not not(black).] d ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
Steven D'Aprano Wrote in message: > On Wed, Feb 12, 2014 at 02:08:17PM -0500, Dave Angel wrote: >> Marc Eymard Wrote in message: >> > ___ >> > Tutor maillist - Tutor@python.org >> > To unsubscribe or change subscription options: >> > https://mail.python.org/mailman/listinfo/tutor >> > >> Next time please post in text form rather than html, and actually >> include the code you're asking us to comment on. > > Dave, your tools are letting you down. Marc did post in text, and did > include his code, as you can see from the multipart attachments to his > email: > > I 1 [multipa/alternativ, 7bit, 2.0K] > I 2 ââ> [text/plain, quoted, iso-8859-1, 0.7K] > I 3 ââ> [text/html, quoted, iso-8859-1, 1.0K] > A 4 coinflip.py [text/x-script.p, base64, us-ascii, 0.6K] > A 5 coinflip_WRONG.py [text/x-script.p, base64, us-ascii, 0.6K] > I 6 [text/plain, 7bit, us-ascii, 0.2K] > > > Perhaps it is time for you to give up on whatever tool you are using to > read this mailing list, or at least to change your assumption when you > see a contentless message from "Original poster didn't send email" to "I > can't see the email". > He posted in html and included two attachments. His email program added added a text version, which we know is frequently bogus. The nntp news system tossed the attachments, I believe. Now, my newsreader (nntp NewsReader, which is the best I've found for my tablet) has bugs, but not as important as the ones I've stopped using. I can read the html version of the email, but when replying it quotes none of it. Sometimes I just give up, sometimes I use copypaste and sometimes I just mention it. But I don't mention it anymore if it's the only thing I have to say. Are you recommending we ignore newsreader usage, or am I permitted to object to attachments? Do you have another suggestion for me, other than: 1) switch to googlegroups 2) read and post only occasionally, when I get back to my laptop 3) write my own reader that runs on the Android -- DaveA ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 09:30:22PM +, Neil Cerutti wrote: > > Perhaps it is time for you to give up on whatever tool you are > > using to read this mailing list, or at least to change your > > assumption when you see a contentless message from "Original > > poster didn't send email" to "I can't see the email". > > This is also a USENET newsgroup, where attachements are not a > thing. Not officially :-) There may be unofficial mirrors of this mailing list on Usenet, but officially (according to python.org) it is a mailing list. The canonical source and archive for this is here: https://mail.python.org/mailman/listinfo/tutor There are other unofficial mirrors, e.g. here: http://code.activestate.com/lists/python-tutor/99298/ and gmane.comp.python.tutor, which by the way shows Marc's post in full, all four of his plain text, HTML, and two .py parts, AND the plain text footer added by the mailman software. Of course attachments are "a thing" in Usenet. One of the reasons so few ISPs offer News services these days is because of the *huge* volume of attachments on binary news groups. Any news client that can't at least *receive* attachments is a major failure. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 10:31:51PM +0100, spir wrote: > On 02/12/2014 10:14 PM, Steven D'Aprano wrote: > >The first thing to notice is that by the logic of the task, each flip > >must be either a Head or a Tail, so the number of Heads and the number > >of Tails should always add up to the number of flips. So you don't need > >to record all three variables, you only need two of them. [...] > * That one needs only to count one eveny kind is accidental, just because > there are here only 2 event kinds, so that number of tails+heads=flips. That is not accidental. That is fundamental to the idea of tossing a coin to get Heads or Tails. Even if you generalise to more than two different events, the sum of each event equals the total number of events. Unless you are forgetting to count some events, or counting other events twice, how can it be otherwise? > In > the general case, Marc's solution to count each even kind is just right. In the *general case* of counting events that occur in N different kinds, the total number of events is equal to the sum of each count. So if there are six different events, plus the total: heads tails hearts spades diamonds clubs total you don't need to record all seven counts (although of course you can if you wish) but just six of them, and work out the seventh: total = sum of heads, tails, hearts, spades, diamonds and clubs or heads = total - sum of tails, hearts, spades, diamonds and clubs for example. In the language of statistics, we say that there are six degrees of freedom here (the six kinds of events) but seven variables. Any one of those variables is completely determined by the other six. > [To compare, there are people using bools to represent 2 distinct cases (eg > black & white in a chass game), and it's conceptually wrong: white is not > not(black).] Of course it is. If x ∈ {White, Black}, then if x is not White, then it must be Black. There are no other options. There is a one:one correspondence between any two-element set and {White, Black}: white, black = ChessColour("white"), ChessColour("black") white, black = "white", "black" white, black = 0, 255 white, black = 255, 0 white, black = -1, 1 white, black = True, False whichever solution makes your code simpler, more efficient, more easily understood, etc. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Wed, Feb 12, 2014 at 05:26:26PM -0500, Dave Angel wrote: > He posted in html and included two attachments. His email program > added added a text version, which we know is frequently bogus. "Frequently?" I don't think so. I hardly ever see text parts which don't say the same thing as the html part, modulo changes to indentation. I can't say "never", as I have seen a few commercial emails (usually advertising) that say "If you cannot read the body of this email, upgrade your email program" instead of a formatting-free version of their HTML part. (Which, by the way, is incredibly rude of them.) But in general, the text part and the html part match very closely, if not exactly. > The nntp news system tossed the attachments, I believe. If you check out the gmane.comp.python.tutor mirror, you will see the attachments. > Now, my newsreader (nntp NewsReader, which is the best I've > found for my tablet) has bugs, but not as important as the ones > I've stopped using. I can read the html version of the email, but > when replying it quotes none of it. Sometimes I just give up, > sometimes I use copypaste and sometimes I just mention it. But I > don't mention it anymore if it's the only thing I have to > say. > > Are you recommending we ignore newsreader usage, or am I permitted > to object to attachments? > Do you have another suggestion for me, other than: > > 1) switch to googlegroups > 2) read and post only occasionally, when I get back to my laptop > 3) write my own reader that runs on the Android As I said in my earlier response, I think it's time for you to switch your default assumption from "the original poster didn't send a plain text message" to "unless other people on the mailing list complain, there probably is a plain text component, I just can't see it". I'm sorry that your technology is letting you down. I'm even more sorry that your current choice is the least worst of a bunch of even worse choices. (Googlegroups? Ew.) I'm afraid that the tech world is going to keep getting worse and worse in this regard, as more and more sites and programmers make unjustified assumptions about what technology is available to the reader. My pet bugbear is websites that don't degrade gracefully when Javascript is turned off, but are essentially unreadable. Worse, sites that are unusable unless you allow Facebook and other spyware sites to run code in your browser. But you've admitted that your tool of choice has limitations, and I don't think it is either fair or useful to rail against the sender for the limitations in your news reader. It's not 1990 any more, and the battle against HTML mail has well and truly be lost. (More's the pity, in my opinion.) I don't know if this works for you, but can you not get mail on your tablet? Perhaps you could read this via the mailing list? -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Beginner - explaining 'Flip a coin' bug
On Thu, Feb 13, 2014 at 10:25:04AM +1100, Steven D'Aprano wrote: > On Wed, Feb 12, 2014 at 05:26:26PM -0500, Dave Angel wrote: > > The nntp news system tossed the attachments, I believe. > > If you check out the gmane.comp.python.tutor mirror, you will see the > attachments. Er, that is to say, if you check out the mirror using a newsreader that shows attachments, you will see the attachments. Anyway, enough metadiscussion about the technology used by this forum. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Regular expressions
Hi all, I am using ipython. 1 ) Defined a string. In [88]: print string foo foobar 2) compiled the string to grab the "foo" word. In [89]: reg = re.compile("foo",re.IGNORECASE) 3) Now i am trying to match . In [90]: match = reg.match(string) 4) Now i print it. In [93]: print match.group() foo Correct me if i am wrong, i am expecting both "foo" and "foobar", why is it giving just "foo" Thanks, santosh ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Regular expressions
Santosh Kumar wrote: > Hi all, > > I am using ipython. > > 1 ) Defined a string. > > In [88]: print string > foo foobar > > 2) compiled the string to grab the "foo" word. > > In [89]: reg = re.compile("foo",re.IGNORECASE) > > 3) Now i am trying to match . > > In [90]: match = reg.match(string) > > 4) Now i print it. > > In [93]: print match.group() > foo > > Correct me if i am wrong, i am expecting both "foo" and "foobar", why is > it giving > just "foo" re.match always gives at most one match, and that match has to start at the beginning of the string: >>> import re >>> r = re.compile("foo", re.I) >>> help(r.match) Help on built-in function match: match(...) match(string[, pos[, endpos]]) --> match object or None. Matches zero or more characters at the beginning of the string >>> r.match("bar foobar") >>> Use re.findall() if you need all matches >>> r.findall("foo FOObar") ['foo', 'FOO'] or re.finditer() if you need other information than just the matching string: >>> [m.start() for m in r.finditer("foo FOObar")] [0, 4] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor