Re: [Tutor] Question about equality of sets

2014-04-06 Thread spir
On 04/05/2014 07:46 PM, Jim Byrnes wrote: Ubuntu 12.04 python 3.3 I was working through an exercise about sets. I needed to find the duplicates in a list and put them in a set. I figured the solution had to do with sets not supporting duplicates. I finally figured it out but along the way I wa

Re: [Tutor] One on one tutor

2014-04-06 Thread spir
On 04/05/2014 01:49 AM, Keith Adu wrote: Hi my name is Keith, am a beginner with no experience in python or computer science. Am looking for someone to work with me one on one, I have many question that I need answered, my question are basic as of the moment because am starting, I don't wan

Re: [Tutor] conditional execution

2014-04-02 Thread spir
On 04/01/2014 06:24 PM, Zachary Ware wrote: Hi Patti, On Tue, Apr 1, 2014 at 11:07 AM, Patti Scott wrote: I've been cheating: comment out the conditional statement and adjust the indents. But, how do I make my program run with if __name__ == 'main': main() at the end? I thought I understood

Re: [Tutor] Slices of lists of lists

2014-03-28 Thread spir
On 03/28/2014 10:42 AM, Jose Amoreira wrote: [...] If we want to access individual rows of this matrix like object, the standard slice notation (on the second index) works as expected also: In [3]: l[0][:] Out[3]: [11, 12, 13] In [4]: l[1][:] Out[4]: [21, 22, 23] Again, fine! No! You *made

Re: [Tutor] Help Noob Question

2014-03-28 Thread spir
On 03/28/2014 02:17 AM, Alan Gauld wrote: On 27/03/14 21:01, Chris “Kwpolska” Warrick wrote: On Mar 27, 2014 8:58 PM, "Alan Gauld" mailto:alan.ga...@btinternet.com>> wrote: > > On 27/03/14 06:43, Leo Nardo wrote: >> >> Im on windows 8 and i need to open a file called string1.py that is on >

Re: [Tutor] 2 Very basic queries

2014-03-26 Thread spir
On 03/26/2014 02:32 AM, Jim Byrnes wrote: 2. Another problem is that the Python shell is allowing me to copy/paste any code at all. Is there something I am not doing right? I was able to copy from idle using Ctrl-C and paste to my newreader using Ctrl-V and then copy from my newsreader back to

Re: [Tutor] character counting

2014-03-23 Thread spir
On 03/23/2014 07:28 AM, Mustafa Musameh wrote: Hi; I have a file that looks like this: title 1 AAATTTGGGCCCATA... TTAACAAGTTAAAT… title 2 AAATTTAAACCC… ATATATATA… … I wrote the following to count the As, Cs, Gs anTs for each title I wrote the following import sys file = open('file.fna'

Re: [Tutor] please help

2014-03-22 Thread spir
On 03/21/2014 10:39 PM, Cameron Simpson wrote: On 21Mar2014 20:31, Mustafa Musameh wrote: Please help. I have been search the internet to understand how to write a simple program/script with python, and I did not do anything. I have a file that look like this ID 1 agtcgtacgt… ID 2 aaaa

Re: [Tutor] Fib sequence code assignment

2014-03-22 Thread spir
On 03/21/2014 10:21 PM, Gary wrote: Dear Jerry, Thank you so much, once you see it it seems so clear, but to see it I might as well be in the Indian Ocean. Got kinda close using temporary variable,but didn't know enough to use del. A lesson learn. You don't need del (here). Every variable i

Re: [Tutor] Understanding code line

2014-03-22 Thread spir
On 03/21/2014 06:14 PM, Gary wrote: Pythonists I am trying to understand the difference between a = b b = a + b and a,b = b, a+ b When used in my Fibonacci code the former generates 0,1,2,4,8,16,32 and the later Generates 0,1,1,2,3,5,8,13,21,34,55,89. The second is the sequence I want, bu

Re: [Tutor] (no subject)

2014-03-22 Thread spir
On 03/21/2014 09:57 PM, Jerry Hill wrote: On Fri, Mar 21, 2014 at 3:25 PM, Gary Engstrom wrote: I am trying to understand function fibc code line a,b = b, a + b and would like to see it written line by line without combining multiply assignment. If possible. I sort of follow the right to left e

Re: [Tutor] Multiple for and if/else statements into a single list comprehension

2014-03-17 Thread spir
On 03/17/2014 11:22 AM, Jignesh Sutar wrote: Is it possible to get two nested for statements followed by a nested if/else statement all into a single list comprehension ie. the equivalent of the below: for i in xrange(1,20): for j in xrange(1,10): if j<6: j=int("8"+st

Re: [Tutor] Loop Issue

2014-03-14 Thread spir
On 03/13/2014 04:42 PM, Dave Angel wrote: spir Wrote in message: On 03/13/2014 12:40 AM, Danny Yoo wrote: The context is the beginning of the thread: https://mail.python.org/pipermail/tutor/2014-March/100543.html with the loop: ### while health != 0: ... ### The point, and

Re: [Tutor] Project suggestions

2014-03-13 Thread spir
On 03/13/2014 03:29 AM, Scott W Dunning wrote: Hey Everyone, I just got through doing a Guess-the-number script and was looking for something else to practice on. Do any of you have any suggestions on some things I could work on? Keep in mind I am not only extremely new to python I am new t

Re: [Tutor] Project suggestions

2014-03-13 Thread spir
On 03/13/2014 07:17 AM, Ben Finney wrote: Scott W Dunning writes: I just got through doing a Guess-the-number script and was looking for something else to practice on. Do any of you have any suggestions on some things I could work on? Keep in mind I am not only extremely new to python I am new

Re: [Tutor] Project suggestions

2014-03-13 Thread spir
On 03/13/2014 03:29 AM, Scott W Dunning wrote: Hey Everyone, I just got through doing a Guess-the-number script and was looking for something else to practice on. Do any of you have any suggestions on some things I could work on? Keep in mind I am not only extremely new to python I am new t

Re: [Tutor] Loop Issue

2014-03-13 Thread spir
On 03/13/2014 12:40 AM, Danny Yoo wrote: The context is the beginning of the thread: https://mail.python.org/pipermail/tutor/2014-March/100543.html with the loop: ### while health != 0: ... ### The point, and reason why this loop was (potentially) infinite, is that the condition

Re: [Tutor] Help with Guess the number script

2014-03-12 Thread spir
On 03/12/2014 05:13 AM, Scott Dunning wrote: >> if guess < secret - 10 or guess > secret - 10: > >This is the right idea for cutting the line count but you >have the comparison values wrong. Look back to earlier >emails, you are repeating the same error as before. >Manually think through wha

Re: [Tutor] Help with Guess the number script

2014-03-11 Thread spir
On 03/11/2014 05:07 AM, Scott W Dunning wrote: On Mar 8, 2014, at 3:57 AM, spir wrote: Well done. And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together

Re: [Tutor] Help with Guess the number script

2014-03-11 Thread spir
On 03/11/2014 09:57 AM, Alan Gauld wrote: On 11/03/14 04:07, Scott W Dunning wrote: On Mar 8, 2014, at 3:57 AM, spir mailto:denis.s...@gmail.com>> wrote: And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had

Re: [Tutor] Help with Guess the number script

2014-03-11 Thread spir
On 03/11/2014 04:32 AM, Scott W Dunning wrote: On Mar 8, 2014, at 11:50 AM, Scott dunning wrote: And now that you have the right set of tests you can half the number of lines by combining your if conditions again, like you had in the original post. ie. Bring your hot/cold/warm tests together.

Re: [Tutor] Help with Guess the number script

2014-03-08 Thread spir
On 03/08/2014 10:13 AM, Alan Gauld wrote: On 08/03/14 01:23, Scott W Dunning wrote: On Mar 7, 2014, at 11:02 AM, Alan Gauld wrote: GOT IT!! Finally! Thanks for all of your help!! This is what I got, not sure if it’s correct but it’s working! Well done. And now that you have the right set

Re: [Tutor] Help with Guess the number script

2014-03-07 Thread spir
On 03/07/2014 06:30 AM, Scott W Dunning wrote: I am trying to write a script for class for a game called guess the number. I’m almost done but, I’m having a hard time getting the hints to print correctly. I’ve tried ‘if’’ ‘elif’ nested, it seems like everything….I’m posting my code for the h

Re: [Tutor] How to determine which function code is being called from

2014-03-06 Thread spir
On 03/06/2014 06:00 PM, Jignesh Sutar wrote: Hi I'm trying to exclude a certain line of code if the function is called by another function, see illustration below: def funcA(): print "running from funcA" # print only if running from funcA print "running from funcA or funcB" #print whe

Re: [Tutor] HTML Parser woes

2014-03-04 Thread spir
On 03/04/2014 05:38 PM, Alan Gauld wrote: On 04/03/14 16:31, Steven D'Aprano wrote: On Tue, Mar 04, 2014 at 04:26:01PM +, Alan Gauld wrote: My turn to ask a question. This has me pulling my hair out. Hopefully it's something obvious... [...] And the output looks like: start test Class Va

Re: [Tutor] Help with "Guess the number" script

2014-03-03 Thread spir
On 03/03/2014 11:27 AM, spir wrote: How would you define what these variables represent, using everyday language? My own definitions would lead me to choose the following variable names: guess_text = raw_input(promt) guess_number = int(user_guess) return guess_number sorry

Re: [Tutor] Help with "Guess the number" script

2014-03-03 Thread spir
On 03/03/2014 05:03 AM, Scott W Dunning wrote: Ben Finney makes numerous fine comments already. I'll add a few, some on the same points but but expressed a bit differently (case it helps). This is what Im having trouble with now. Here are the directions I’m stuck on and what I have so far,

Re: [Tutor] Help with "Guess the number" script

2014-03-01 Thread spir
On 03/01/2014 07:46 AM, Scott W Dunning wrote: Hello, i am working on a project for learning python and I’m stuck. The directions are confusing me. Please keep in mind I’m very ne to this. The directions are long so I’ll just add the paragraphs I’m confused about and my code if someone coul

Re: [Tutor] Why does the last loop not work?

2014-02-25 Thread spir
On 02/25/2014 01:59 AM, Gregg Martinson wrote: I am trying to generate a list of teams using objects that I collect into a list that I can cycle through. But when I run the last loop there is nothing produced. Look at your last line of code: x.print_team This is just the _name_ of the m

Re: [Tutor] Class decorator on a derived class not initialising the base classes using super - TypeError

2014-02-24 Thread spir
On 02/24/2014 08:19 PM, Sangeeth Saravanaraj wrote: Sorry, I should have described what I was trying! I want to create a decorator which should do the following things: - When an object of the decorated class is created, the objects name (say the value of the incoming "id" argument) sho

Re: [Tutor] I can't understand where python class methods come from

2014-02-24 Thread spir
On 02/23/2014 10:59 PM, voger wrote: I have a really hard time understanding where methods are defined in python classes. My first contact with programming was with C++ and Java and even if I was messing with them in a very amateurish level, I could find where each class was defined and what meth

Re: [Tutor] constructing semi-arbitrary functions

2014-02-20 Thread spir
On 02/20/2014 01:56 AM, "André Walker-Loud " wrote: On Feb 19, 2014, at 7:45 PM, André Walker-Loud wrote: OK - I have not seen an email from Peter. So I looked up the thread online, and see I did not receive half the emails on this thread :O My first inclination was to blame my mac mavericks

Re: [Tutor] Regular expression - I

2014-02-18 Thread spir
On 02/18/2014 08:39 PM, Zachary Ware wrote: Hi Santosh, On Tue, Feb 18, 2014 at 9:52 AM, Santosh Kumar wrote: Hi All, If you notice the below example, case I is working as expected. Case I: In [41]: string = "test" In [42]: re.match('',string).group() Out[42]: '' But why is the raw string

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/17/2014 08:23 PM, "André Walker-Loud " wrote: Hello python tutors, I am utilizing a 3rd party numerical minimization routine. This routine requires an input function, which takes as arguments, only the variables with which to solve for. But I don’t want to define all possible input fun

Re: [Tutor] constructing semi-arbitrary functions

2014-02-18 Thread spir
On 02/18/2014 12:02 AM, Oscar Benjamin wrote: On 17 February 2014 22:15, "André Walker-Loud " wrote: This particular case is easily solved: def f_lambda(x,pars): return lambda x: poly(x,*pars) You let the closure take care of pars and return a function that takes exactly one argument x.

Re: [Tutor] Performing an union of two files containing keywords

2014-02-17 Thread spir
On 02/17/2014 10:07 AM, Aaron Misquith wrote: I have 2 different text files. File1.txt contains: file RAMPython parser File2.txt contains: file1234 program I want to perform an union of these both files such that i get an output file3.txt which contains: file RAMPython parser1234 program

Re: [Tutor] Beginner - explaining 'Flip a coin' bug

2014-02-12 Thread spir
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'

Re: [Tutor] Better flow for this?

2014-02-12 Thread spir
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

Re: [Tutor] Better flow for this?

2014-02-12 Thread spir
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 mom

Re: [Tutor] trace / profile function calls with inputs

2014-02-10 Thread spir
On 02/08/2014 05:36 PM, Richard Cziva wrote: Hi All, I am trying to print out every function that is being called while my Python program is running (own functions and library calls too). I can not modify the Python programs I am trying to profile. Let me give an example. A program contains a f

Re: [Tutor] Recommendation For A Complete Noob

2014-02-09 Thread spir
On 02/09/2014 11:37 PM, Altrius wrote: Hi, I’m completely new to programming in general and everything I have read so far has pointed me to Python. I’ll put this another way: All I know is that a programming language is a medium for a human to tell a computer what to do. After that I’m kinda

Re: [Tutor] Which computer operating system is best for Python

2014-02-06 Thread spir
On 02/06/2014 02:51 AM, Tim Krupinski wrote: The reason I suggest Linux is because a lot of Python is used in it already. People was also designed (according to Guido vR) to please Unix/C hackers. d ___ Tutor maillist - Tutor@python.org To unsubscr

Re: [Tutor] Which computer operating system is best for Python

2014-02-06 Thread spir
On 02/06/2014 12:13 AM, Alan Gauld wrote: On 05/02/14 18:34, Colin Chinsammy wrote: I am considering purchasing the Acer c720 chromebook for my 13yo to begin learning Python for Kids. Obviously I am on a budget. I wouldn't consider a Chromebpook for anyone learning programming. They are fine f

Re: [Tutor] Advice on Python codes - A recursive function to output entire directory subkeys of Windows Registry

2014-02-06 Thread spir
On 02/05/2014 04:30 PM, Alan Ho wrote: Hi, I am a novice in Python, having attended a course few weeks ago and I'm working on my assignment now, and I encounter this issue when I was trying to print the entire Windows Registry (WR) sub-keys directories (trying that first with the below codes

Re: [Tutor] Splitting email headers when using imaplib

2014-02-04 Thread spir
On 02/04/2014 06:38 PM, Some Developer wrote: I'm currently trying to download emails from an IMAP server using Python. I can download the emails just fine but I'm having an issue when it comes to splitting the relevant headers. Basically I'm using the following to fetch the headers of an email m

Re: [Tutor] Traversing lists or getting the element you want.

2014-02-03 Thread spir
On 02/02/2014 09:46 PM, Kipton Moravec wrote: I am new to Python, and I do not know how to traverse lists like I traverse arrays in C. This is my first program other than "Hello World". I have a Raspberry Pi and they say Python is the language of choice for that little machine. So I am going to t

Re: [Tutor] most useful ide

2014-02-03 Thread spir
On 02/02/2014 09:10 PM, Pierre Dagenais wrote: On 14-02-02 01:16 PM, Kodiak Firesmith wrote: Pycharm is nice for bigger projects (since tou can collapse any section); but it's crazy resource intensive. For Linux Gedit can be made very nice I prefer Geany as it will run my code with a click

Re: [Tutor] most useful ide

2014-02-02 Thread spir
On 02/02/2014 09:10 PM, Pierre Dagenais wrote: On 14-02-02 01:16 PM, Kodiak Firesmith wrote: Pycharm is nice for bigger projects (since tou can collapse any section); but it's crazy resource intensive. For Linux Gedit can be made very nice I prefer Geany as it will run my code with a click

Re: [Tutor] sorting and writing to data file

2014-02-02 Thread spir
On 02/02/2014 04:08 AM, adrian wrote: Hello community, Newbie here. I have a data (.dat) file with integers (2,9,1,5,7,3,9) in it just as shown. My instructions are to sort the numbers and rewrite them back to the data file. *here is my code:** * lab3int=[2,9,1,5,7,3,9] lab3int.sort() print(la

Re: [Tutor] creating Turtle() object using 2 different ways

2014-02-01 Thread spir
On 01/31/2014 10:38 PM, Alan Gauld wrote: If you want multiple turtles you should use the first version. Yes, the turtle module has a global turtle that can be used by people playing with a single turtle, and prefere conventional procedural programming style, rather than object-oriented (OO).

Re: [Tutor] Unit testing infinite loops

2014-01-31 Thread spir
On 01/31/2014 12:31 PM, James Chapman wrote: try: while self.attribute: time.sleep(1) except KeyboardInterrupt: Maybe I'm missing apoint or reasoning wrongly, but I'd rather do: while self.attribute: try: time.sleep(1) except KeyboardInterrupt: ... or something lik

Re: [Tutor] When is = a copy and when is it an alias

2014-01-29 Thread spir
On 01/29/2014 02:34 AM, Denis Heidtmann wrote: Glad to hear it. That is what I was hoping, but I did not want to question a helpful person. (you could & should, we need helpful feedback too, to improve our skills; i mean, as long as it's honest indeed) d

Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread spir
On 01/29/2014 02:10 AM, Dave Angel wrote: Denis Heidtmann Wrote in message: What is going on? I am more confused than I was a week ago. Simple. spir has copy/paste editing errors. Oops! sorry d ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] If, elif, else

2014-01-28 Thread spir
On 01/28/2014 11:46 PM, Michael L. Pierre wrote: I am a newbie with Python (programming in general) and I am trying to create a program that will take user name and dob and pump out their age, while on a person's birthday the output not only states their name and age, but also prints out ***HA

Re: [Tutor] When is = a copy and when is it an alias

2014-01-28 Thread spir
On 01/27/2014 06:04 PM, Denis Heidtmann wrote: Apparently a[0]=b[0] does not qualify as "symbolic assignment" in this case. a[0] is not a reference to b[0]. I think I see the essential distinction. Experience will complete the picture for me. "symolic assignment" is my term, so whatever I mea

Re: [Tutor] Multi Layered Graphs

2014-01-27 Thread spir
On 01/26/2014 11:23 PM, Ankit Arora wrote: I'm working on a project which involves network graphs. Is there a library that can help me do this: I want to create multi-layered graphs i.e. graphs which contain a set number of vertices but multiple 'layers' of edges i.e. same set of vertices repres

Re: [Tutor] When is = a copy and when is it an alias

2014-01-27 Thread spir
On 01/27/2014 07:16 AM, Denis Heidtmann wrote: Running python 2.7 in linux Below are two extremes. Can I get some guidance on this? Thanks, -Denis H a=zeros((2,3),dtype=int) b=a a[:,0]=[1,2] a array([[1, 0, 0], [2, 0, 0]]) b array([[1, 0, 0], [2, 0, 0]]) a=2 a 2 b arra

Re: [Tutor] How to correct decimal addition.

2014-01-26 Thread spir
On 01/26/2014 04:22 AM, Keith Winston wrote: On Sat, Jan 25, 2014 at 5:09 PM, Oscar Benjamin wrote: Perhaps it would be better though to point at this: round(D('0.123456'), 3) Decimal('0.123') I think you are right. I didn't even think of round(). I think we have confounded two issues in th

Re: [Tutor] code works in windows command but not ubuntu terminal

2014-01-25 Thread spir
On 01/26/2014 02:12 AM, Steven D'Aprano wrote: On Sat, Jan 25, 2014 at 09:11:56AM +0100, spir wrote: As a foreigner, I noticed that english native speakers use both the series round / square / curly / angle brackets, and individual terms parens (no 'd' ;-) / brackets / braces

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:38 PM, Keith Winston wrote: Also, just to be clear: I'd suggest floats because decimal requires importing a module and using the non-built-in features thereof The issue is not that much whether it's supported by builtins, in software, but by CPU's; which is not the case, so th

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:19 PM, Keith Winston wrote: On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: Note: AFAIK most financial software use integers for this reason and to avoid (or control) rounding errors. I don't think this is true (no flame intended, hopefully you know I'm forever in

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 10:01 PM, Keith Winston wrote: On Sat, Jan 25, 2014 at 3:57 AM, spir wrote: .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I have tried and the results of it. def gas_price(price

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/25/2014 09:46 AM, spir wrote: On 01/24/2014 06:57 PM, Leon S wrote: Here is what I'm trying to do, accept a price of gas, but I want to add the .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I

Re: [Tutor] How to correct decimal addition.

2014-01-25 Thread spir
On 01/24/2014 06:57 PM, Leon S wrote: Here is what I'm trying to do, accept a price of gas, but I want to add the .009 to the price, so that people do not have to type the full amount. Example, 3.49 /gallon would return 3.499 /gallon. This is what I have tried and the results of it. def gas_p

Re: [Tutor] code works in windows command but not ubuntu terminal

2014-01-25 Thread spir
On 01/25/2014 05:14 AM, Steven D'Aprano wrote: On Fri, Jan 24, 2014 at 10:28:09PM -0500, bob gailer wrote: And please call () parends and [] brackets, and{} braces. Saves a lot of confusion. If you think that parentheses are spelt with a "d", you're certainly confused :-) They're all bracket

Re: [Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread spir
On 01/25/2014 04:13 AM, eryksun wrote: On Fri, Jan 24, 2014 at 8:50 AM, spir wrote: xs is an iterator (__next__ is there), then Python uses it directly, thus what is the point of __iter__ there? In any case, python must check whether Python doesn't check whether a type is alrea

Re: [Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread spir
On 01/24/2014 06:44 PM, Peter Otten wrote: There is no infinite recursion. The for loop is currently implemented as # expect an iterable # handle iterators through an idempotent iter() tmp = iter(xs) # here you must check that tmp actually implements the iterator protocol, # else raise an erro

Re: [Tutor] Iterator vs. iterable cheatsheet, was Re: iter class

2014-01-24 Thread spir
On 01/24/2014 10:22 AM, Peter Otten wrote: There's an odd outlier that I probably shouldn't tell you about [...] I guess there is a whole class of outliers; not really sure how to classify them. This is the case of defining a wrapper or "proxy" type, for a underlying data structure which is

Re: [Tutor] iter class

2014-01-23 Thread spir
On 01/23/2014 06:53 AM, Keith Winston wrote: I suppose I should practice running my questions on old code through 2to3 before I pester the Tutor list, since that's probably also a good way to learn the differences. Yes, but that way others learn as well :-) And many people prefere learning via

Re: [Tutor] Stuck on Challenge in Google Python Class

2014-01-22 Thread spir
On 01/22/2014 05:24 AM, Adam Hurwitz wrote: Hi, This is a coding challenge in the Google Developers Python Course. I have been working on this challenge for hours without being able to solve. A. match_ends # Given a list of strings, retu

Re: [Tutor] How to print certain elements

2014-01-21 Thread spir
On 01/21/2014 07:18 AM, Adriansanchez wrote: Hello everyone, I am newbie to Python and programming in general. My question is, given a list: X=['washington','adams','jefferson','madison','monroe'] And a string: Y='washington,adams,jefferson,madison,monroe' Side note: you can generate X automati

Re: [Tutor] Understanding Classes

2014-01-21 Thread spir
On 01/21/2014 05:20 AM, Christian Alexander wrote: Alan, The concept and purpose of classes is starting to sink in a little bit, but I still haven't had my "Ah-ha" moment yet. I just can't seem to visualize the execution of classes, nor am I able to explain to myself how it actually works. Fo

Re: [Tutor] Understanding Classes

2014-01-20 Thread spir
On 01/19/2014 10:59 PM, Christian Alexander wrote: Hello Tutorians, Looked all over the net for class tutorials Unable to understand the "self" argument Attempting to visual classes I have searched high and low, for easy to follow tutorials regarding classes. Although I grok the general concep

Re: [Tutor] string indexing -- side note, rather OT

2014-01-20 Thread spir
On 01/20/2014 01:19 AM, Keith Winston wrote: On Sun, Jan 19, 2014 at 3:50 PM, Alan Gauld wrote: How would Python know whether you want find for gettext, mmap, str, xml.etree.ElementTree.Element or xml.etree.ElementTree.ElementTree? Absolutely, but a newbie doesn't even guess that more than o

Re: [Tutor] string indexing

2014-01-19 Thread spir
On 01/19/2014 02:59 PM, rahmad akbar wrote:> hey guys, super noob here, i am trying to understand the following code from google tutorial which i failed to comprehend #code start # E. not_bad # Given a string, find the first appearance of the # substring 'not' and 'bad'. If the 'bad' follows #

Re: [Tutor] Naming variables

2014-01-19 Thread spir
On 01/19/2014 02:59 PM, Mark Lawrence wrote: On 19/01/2014 13:23, spir wrote: On 01/18/2014 07:20 PM, Pierre Dagenais wrote: Hello, I wish to fill a list called years[] with a hundred lists called year1900[], year1901[], year1902[], ..., year1999[]. That is too much typing of course. Any way

Re: [Tutor] Naming variables

2014-01-19 Thread spir
On 01/18/2014 07:20 PM, Pierre Dagenais wrote: Hello, I wish to fill a list called years[] with a hundred lists called year1900[], year1901[], year1902[], ..., year1999[]. That is too much typing of course. Any way of doing this in a loop? I've tried stuff like ("year" + str(1900)) = [0,0] but n

Re: [Tutor] iterators

2014-01-19 Thread spir
On 01/19/2014 12:24 AM, Keith Winston wrote: On Sat, Jan 18, 2014 at 2:19 PM, eryksun wrote: `xrange` and 3.x `range` aren't iterators. They're sequences. A sequence implements `__len__` and `__getitem__`, which can be used to implement an iterator, reversed iterator, and the `in` operator (i.e

Re: [Tutor] iterators -- oops!

2014-01-18 Thread spir
erratum: On 01/18/2014 12:13 PM, spir wrote: [Note, just to compare: in Lua, this little magic making builtin sequences special does not exist. So, to iterate over all items or pairs of a Lua table, one would write explicitely, resp.: for key,val in pairs(t) for item in ipairs(t

Re: [Tutor] iterators

2014-01-18 Thread spir
On 01/18/2014 09:51 AM, Keith Winston wrote: I don't really get iterators. I saw an interesting example on Stackoverflow, something like with open('workfile', 'r') as f: for a, b, c in zip(f, f, f): And this iterated through a, b, c assigned to 3 consecutive lines of the file as it it

Re: [Tutor] lambdas, generators, and the like

2014-01-16 Thread spir
On 01/12/2014 10:04 AM, Keith Winston wrote: I've got this line: for k in range(len(tcombo)): tcombo_ep.append(list(combinations(tcombo, k+1))) generating every possible length combination of tcombo. I then test them, and throw most of them away. I need to do this differently, it gets way

Re: [Tutor] lambdas, generators, and the like

2014-01-16 Thread spir
's written like a list comprehension, bit with () instead of []. The semantic difference is that items are generated once at a time instead of all in one go and stored in a list. Another difference is that one cannot reuse such a generator object (once end is reached, it is like "e

Re: [Tutor] Python Question

2014-01-10 Thread spir
On 01/10/2014 01:11 AM, Amy Davidson wrote: Hi, I am a university student who is struggling with writing functions in Python. I’ve been attempting to write a function in Python for over 2 hours with no progress. The function must be called, printID and take a name and student number as parame

Re: [Tutor] recursion depth

2014-01-08 Thread spir
rammer feedback. Guess it has to do with cycles, but there are ways to do that; and python manages cycles in list expressions: spir@ospir:~$ python3 Python 3.3.1 (default, Sep 25 2013, 19:29:01) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license&q

Re: [Tutor] garbage collecting

2014-01-08 Thread spir
On 01/08/2014 10:30 AM, Keith Winston wrote: well, fair enough. Generally, the issue involves instances when Python will come back, but it might take several minutes or much longer. And weird behaviour ensues: like timers I put on the program don't actually time the amount of time it's busy (by a

Re: [Tutor] More or less final Chutes & Ladders

2014-01-06 Thread spir
On 01/05/2014 08:40 PM, Keith Winston wrote: On Sun, Jan 5, 2014 at 2:52 AM, Mark Lawrence wrote: Homework for you :) Write a line of code that creates a list of say 3 or 4 integers, then write a line that creates a tuple with the same integers. Use the dis module to compare the byte code th

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 08:57 AM, Alex Kleider wrote: On 2014-01-04 21:20, Danny Yoo wrote: Oh! That's unfortunate! That looks like a bug on the hostip.info side. Check with them about it. I can't get the source code to whatever is implementing the JSON response, so I can not say why the city is not

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 03:31 AM, Alex Kleider wrote: I've been maintaining both a Python3 and a Python2.7 version. The latter has actually opened my eyes to more complexities. Specifically the need to use unicode strings rather than Python2.7's default ascii. So-called Unicode strings are not the solut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/04/2014 08:26 PM, Alex Kleider wrote: Any suggestions as to a better way to handle the problem of encoding in the following context would be appreciated. The problem arose because 'Bogota' is spelt with an acute accent on the 'a'. $ cat IP_info.py3 #!/usr/bin/env python3 # -*- coding : ut

Re: [Tutor] encoding question

2014-01-05 Thread spir
On 01/05/2014 12:52 AM, Steven D'Aprano wrote: If you don't understand an exception, you have no business covering it up and hiding that it took place. Never use a bare try...except, always catch the *smallest* number of specific exception types that make sense. Better is to avoid catching except

Re: [Tutor] More or less final Chutes & Ladders

2014-01-05 Thread spir
On 01/05/2014 08:52 AM, Mark Lawrence wrote: On 05/01/2014 07:09, Keith Winston wrote: Thanks all, interesting. I'll play more with tuples, I haven't knowingly used them at all... Keith Homework for you :) Write a line of code that creates a list of say 3 or 4 integers, then write a line t

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 02:03 PM, Steven D'Aprano wrote: >I'm also a bit confused here: obviously tuples are immutable, but one can >use lists in them... I think that makes those lists' contents immutable? Nope. It makes the tuple immutable in the sense that it's *direct* contents cannot be changed, but m

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 02:03 PM, Steven D'Aprano wrote: >I understand that Python doesn't have composite objects, but neither does >it dislallow my list of lists of ints and lists... which is, I imagine, >very space efficient. I'm afraid I have no idea what you mean by Python not having "composite object

Re: [Tutor] More or less final Chutes & Ladders

2014-01-04 Thread spir
On 01/04/2014 12:33 PM, Keith Winston wrote: Thanks Alan & Denis: Alan, the improvement you suggested had already been made, and adopted. Good catch. Denis: alas, there are chutes and ladders dicts, but I guess your chutes & ladders lists are local to the results class... Your suggestion is quit

Re: [Tutor] python, speed, game programming

2014-01-04 Thread spir
On 01/04/2014 02:38 AM, Keith Winston wrote: The thing that put me on edge was noticing that my simple Chutes & Ladders game doesn't go ANY faster on a machine that benchmarks perhaps 1000 times faster than another... You could say this about most programs in most langs. Actually, some even re

Re: [Tutor] python, speed, game programming

2014-01-04 Thread spir
On 01/04/2014 10:14 AM, Steven D'Aprano wrote: While I agree with Devin, it is possible to write absurdly slow code in *any* language. This is why is is better to write straightforward, simple code in preference to complicated, intricate code -- it is easier to understand simple code, which means

Re: [Tutor] Copying [was Re: What's in a name?]

2014-01-04 Thread spir
On 01/04/2014 07:24 AM, Keith Winston wrote: I had heard about deep/shallow copies, though in this particular example (all int dicts), I don't think there's a difference...? There's none, you're right. It's only whenever inner items (fields, etc...) themselves are complex elements and mutable.

Re: [Tutor] Fwd: What's in a name?

2014-01-04 Thread spir
On 01/04/2014 06:36 AM, Steven D'Aprano wrote: Now, it's true that when *debugging code*, being able to see the name of the variable and the contents of the variable is useful. But in ordinary code, why would you care to print the name of the variable and its contents. Who cares what the variable

Re: [Tutor] What's in a name?

2014-01-04 Thread spir
On 01/04/2014 06:32 AM, Keith Winston wrote: On Fri, Jan 3, 2014 at 11:59 PM, Steven D'Aprano wrote: thelist = vars()[name] I see: vars() certainly looks less dangerous than eval(), but I'm guessing that's still smelly code? I hadn't known about vars() or I probably would have used it. It

Re: [Tutor] simple arg problem

2014-01-04 Thread spir
On 01/04/2014 05:45 AM, Steven D'Aprano wrote: On Fri, Jan 03, 2014 at 09:56:25PM -0500, Keith Winston wrote: gmail is driving me crazy. Anyway, every time I run it with: if __name__ == "__main__": tarray = CandL_Array tarray.populate(100) I get an error Traceback (most recent call

  1   2   3   4   5   6   7   >