Re: [Tutor] python programmin problem

2016-07-23 Thread Danny Yoo
On Thu, Jul 21, 2016 at 11:30 PM, Alan Gauld via Tutor wrote: > > Forwarding to list. Please use reply-all when responding to tutor messages. > > As Danny suggested this is quite a complex problem. I wasn't sure whether > it was just the programming or the bigger algorithm issue you were stuck on.

Re: [Tutor] python programmin problem

2016-07-24 Thread Danny Yoo
On Jul 23, 2016 9:27 AM, "monik...@netzero.net" wrote: > > IM sorry I do not understand: > > For array A of length N, and for an integer k < N: > -- By k do you mean value of k or position of k in the list? > The letter 'k' is typically intended to be used as an index, a position into a list. I'

Re: [Tutor] python programmin problem

2016-07-24 Thread Danny Yoo
> You probably want to use a problem that has fewer moving parts. Your instructor likely has a much nicer introductory problem so that you can learn the patterns of thinking through these problems. Just to add: there are online resources you can use for this. Khan Academy, for example: https://w

Re: [Tutor] python programmin problem

2016-07-27 Thread Danny Yoo
On Sun, Jul 24, 2016 at 4:30 PM, monik...@netzero.net wrote: > Thank you all for your answers. I do not have a teacher or any body else who > could guide me. I have taken all python classes offered in my area and many > on line. > The question is one of questions asked by interviews for a qa pos

Re: [Tutor] python programmin problem

2016-07-27 Thread Danny Yoo
> You will see a problem being explained that you should be *very* > interested in. :) Here's a link just to give you a taste: > > https://youtu.be/0yjebrZXJ9A?t=3m > > > I hope that this helps point you in the right direction. Good luck! He has some more recent videos from 2012: htt

Re: [Tutor] Book recommendation

2016-08-01 Thread Danny Yoo
> One area that is especially troublesome is knowledge of > math. Programming is rooted in math and professional > programmers will have studied math in depth but many > amateur beginners may only have junior school math > level. But how do you find out? > > It's a perennial problem when experts tr

Re: [Tutor] Python Assignment

2016-08-01 Thread Danny Yoo
On Mon, Aug 1, 2016 at 8:18 AM, Justin Korn via Tutor wrote: > To whom it may concern, > I need someone to help me to develop programs for the following assignments. You've asked a few questions earlier: https://mail.python.org/pipermail/tutor/2016-July/109403.html https://mail.python.

Re: [Tutor] data storage question

2016-08-01 Thread Danny Yoo
I agree with Steven; JSON is probably one of the most popular formats for saving structured data externally, and it's probably the lightweight approach to use in this situation. By the way, it looks like you're already dealing with a certain file format in your program. In fact, it looks like a s

Re: [Tutor] data storage question

2016-08-01 Thread Danny Yoo
One other thing: you might hear another popular approach is to use the "pickle" module. I don't think it'd be appropriate for your situation because it would be overkill for the problem you're describing. JSON is safer: if you have to choose between JSON and pickle, use JSON. --- More curmudgeo

Re: [Tutor] Problem with code interating thri a list

2016-08-02 Thread Danny Yoo
On Tue, Aug 2, 2016 at 7:59 AM, Chris Clifton via Tutor wrote: > My Logic: Since a string is immutable, I converted it to a list to separate > out the characters and keep them in order. Idea is to change the case of the > characters in the list then run a join to convert it back to a string.

Re: [Tutor] data storage question

2016-08-03 Thread Danny Yoo
> Based on both replies I got, JSON is what I will use. > > I do need the keys in the dictionary to be numerals, specifically they are > integers. > > I believe after I load a stored pt_table, I can use this script to convert > the keys back to integers. > > pt_table = dict((int(key), value) for

Re: [Tutor] Problem

2016-08-28 Thread Danny Yoo
On Sun, Aug 28, 2016 at 7:46 AM, shahan khan wrote: > Hello > I'm teching myself Python using MIT opencourse ware. I'm a beginner and > have some what knowledge of c and c++. I'm using Python version > Here is my code: [code cut] Before showing code, try to express what you're trying to do in

Re: [Tutor] python coding problem

2016-09-26 Thread Danny Yoo
Hi Richard, The "return" statement does an early escape out of the currently running function. You have a "return" statement in your program that looks unintentional. In an ideal world, the Python compiler would give a warning about this because it's a common mistake. Unfortunately it looks lik

Re: [Tutor] differences between map and partial?

2016-09-27 Thread Danny Yoo
On Tue, Sep 27, 2016 at 2:23 AM, source liu wrote: > Hi, List > > the test code as attached Unfortunately, it didn't attach. If you can inline the content of the test code, that would be helpful. > this one works print p.map(partial(file_op,lineop=unity),input) > this one doesn't

Re: [Tutor] Help regarding reg exp.

2016-10-05 Thread Danny Yoo
> On 05/10/16 10:03, rakesh sharma wrote: >> Hi all >> >> I have a string of pattern ({A,BC},{(A,B),(B,C)(C,A)}. > On Wed, Oct 5, 2016 at 3:14 AM, Alan Gauld via Tutor wrote: > Until we understand the data better we can't be sure > a regex is the best solution. Yes, I agree with Alan: we need t

Re: [Tutor] Accessing Yahoo with Python?

2016-10-09 Thread Danny Yoo
On Sat, Oct 8, 2016 at 3:29 PM, Jim Byrnes wrote: > I realize that my question is not about the standard library. The only > reason I am asking here is, if I remember correctly, a regular contributor, > Danny Yoo, works at Yahoo. I am hoping he, or someone else here can help me > und

Re: [Tutor] Adding numbers within a string

2016-10-12 Thread Danny Yoo
Please do not give homework solutions. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] a bit off topic.. - more of a high level arch question!

2016-10-21 Thread Danny Yoo
> Thinking of a situation where I have two "processes" running. They > each want to operate on a list of files in the dir on a first come > first operate basis. Once a process finishes with the file, it deletes > it. > > Only one process operates on a file. > > I'm curious for ideas/thoughts. Hi

Re: [Tutor] comp.lang.python on gmane

2016-10-27 Thread Danny Yoo
On Thu, Oct 27, 2016 at 5:40 PM, Jim Byrnes wrote: > Is comp.lang.python available on gmane? > > I've googled and found references to it being on gmane but I can't find it > there. I'd like to use gmane because Comcast doesn't do usenet anymore. Hi Jim, I think Gmane is still recovering: h

Re: [Tutor] New to Python

2016-10-27 Thread Danny Yoo
> program-they just do it. Also noticed-when starting new file sometimes I > see run at the top sometimes not? Lots of questions. Familiar with > programming in C. If you're a database and C developer, then you probably have enough experience to go through the Python tutorial, as it is aimed for

Re: [Tutor] comp.lang.python on gmane

2016-10-28 Thread Danny Yoo
>>> >>> Is comp.lang.python available on gmane? >>> >>> I've googled and found references to it being on gmane but I can't find >>> it there. I'd like to use gmane because Comcast doesn't do usenet >>> anymore. >> >> >> I don't know about the current viability of gmane in general, but it's >> calle

Re: [Tutor] comp.lang.python on gmane

2016-10-28 Thread Danny Yoo
Ah. The wiki link does point to the expected place after all. I think, then, that the initial assessment is accurate, that Gmane is still recovering their archives, and that eventually the link will work again. ___ Tutor maillist - Tutor@python.org To

Re: [Tutor] Python code

2016-11-01 Thread Danny Yoo
On Nov 1, 2016 4:57 PM, "Haley Sandherr" wrote: > > Hello, I am new to python and need help with this question: > > Compose a function odd ( ) that takes three bool arguments and returns True if an odd number of arguments are True and False otherwise. Do you understand all of the terms in the que

Re: [Tutor] Q regarding external program calling

2016-11-05 Thread Danny Yoo
Hi Clayton, I'm not too familiar with development on Windows, unfortunately, but I think the 'subprocess' module is what you're looking for. https://docs.python.org/3/library/subprocess.html For example: http://stackoverflow.com/questions/748028/how-to-get-output-of-exe-in-python-script sh

Re: [Tutor] Regex ^$ not behaving as expected

2016-12-08 Thread Danny Yoo
Hi Edmund, For each of the cases that surprise you, next time, can you also say what you expected to see? That can help us see where the confusion lies; as it stands, if we have the same mental model as what's happening in Python, then the results look correct to us. :P I can guess at what you

Re: [Tutor] Regex ^$ not behaving as expected

2016-12-08 Thread Danny Yoo
> I'm still somewhat confused as to what the regexp module is doing when > passing a non-numeric count parameter. That looks like it should > raise a TypeError to me, so perhaps someone needs to file a bug > against the standard library? Unsure. Ok, I'm filing a bug to the Python developers so

Re: [Tutor] Regex ^$ not behaving as expected

2016-12-08 Thread Danny Yoo
Following up: drats! Detecting this conceptual TypeError is not feasible under the current design, due to the choice of data representation used in this API. The reason is because the flags are being represented as integers, and we're using bitwise operations to define the union of flags. That i

Re: [Tutor] function argument unpacking

2016-12-08 Thread Danny Yoo
On Thu, Dec 8, 2016 at 1:11 AM, Alan Gauld via Tutor wrote: > On 08/12/16 06:04, Palanikumar wrote: >> #Function Argument unpacking >> def myfunc(x, y, z): >> print(x. v. z) >> > > Please always send the actual code that generates > the error, do not retype as it causes us to chase > phantom

Re: [Tutor] How to interact with the result of subprocess.call()

2016-12-24 Thread Danny Yoo
On Sat, Dec 24, 2016 at 2:40 PM, Jim Byrnes wrote: > subprocess.call(['libreoffice', '/home/jfb/test.ods']) > k.tap_key(k.enter_key) > k.tap_key(k.enter_key) > > If I run the above code, libreoffice opens the test.ods spreadsheet then > just sits there. When I close libreoffice the two enter_keys

Re: [Tutor] Another way to strip?

2017-01-19 Thread Danny Yoo
On Jan 19, 2017 4:36 PM, "ad^2" wrote: Hello all, I'm looking for a cleaner more elegant way to achieve stripping out a file name from a list which contains a path and file extension. Would os.path.split help here? https://docs.python.org/3.6/library/os.path.html#os.path.split ___

Re: [Tutor] Find (list) strings in large textfile

2017-02-09 Thread Danny Yoo
Files don't rewind automatically, so once a loop goes through the file once, subsequent attempts will finish immediately. We might fix this by "seek", which will let us rewind files. However, your data is large enough that you might want to consider efficiency too. The nested loop approach is go

Re: [Tutor] Find (list) strings in large textfile

2017-02-11 Thread Danny Yoo
Believe it or not, a change in two characters should make this even faster. :) Change the line: file_list = [i[:-1] for i in my_list.readlines()] to: file_list = {i[:-1] for i in my_list.readlines()} The change is to use a "set comprehension" instead of a "list comprehension". Sets

Re: [Tutor] Q about .join() Thanks!

2017-02-13 Thread Danny Yoo
> That's because dictionaries are not stored sequentially and the > order of retrieval is not guaranteed - it can even change > during the execution of a program so you should never > depend on it. That's because dictionaries are optimised > for random access via the keys not to be iterated over.

Re: [Tutor] Wedscraping Yahoo API

2017-02-20 Thread Danny Yoo
Hi Joe, On Mon, Feb 20, 2017 at 6:32 AM, Joe via Tutor wrote: > Hi, > I keep getting the following error as I am new to programming and I am > following a tutorial and I am using Python 3.6. Can you please point me in > the right direction as to what I am doing wrong. You have made an assump

Re: [Tutor] feedback on simple python code

2017-02-27 Thread Danny Yoo
Hi Ryan, Let's take a look... Overloading the "write" method to take in different types of arguments looks a bit suspicious. You have a superclass that defines a write method, and you have two subclasses that implement that method. However, your first implementation, LogFile.write, appears to

Re: [Tutor] How to get url call back from the browser

2017-03-01 Thread Danny Yoo
Hi Palanikumar, It looks like you're using Python 2, since you're referring to SimpleHTTPServer. But you probably do not want to use SimpleHTTPRequestHandler: it's a local file system server. The docs at https://docs.python.org/2/library/simplehttpserver.html#SimpleHTTPServer.SimpleHTTPRequestH

Re: [Tutor] lambda

2013-01-25 Thread Danny Yoo
On Fri, Jan 25, 2013 at 4:57 PM, anthonym wrote: > I have the code below that I used to create a simple tic tac toe game for > class. I am learning Python but have programmed in C+ before so I brought > over a lambda and found that it worked in Python. Unfortunately I don't > think my classmate

Re: [Tutor] Help!

2013-01-28 Thread Danny Yoo
> Hi guys I wanted to make a program called Binary/decimal converter. But I > want to do it the hard way e.g. not using built in python functions. Can you > give me an idea about how I can do that? Do you have an idea of what kind of things would be useful test cases for this converter? Thinki

Re: [Tutor] automate add-to-cart with python

2013-01-28 Thread Danny Yoo
> Or maybe, just maybe, somebody has written a javascript interpreter in > Python as a module that you can import. It sounds just about crazy enough > that it might even exist! But as I said, that's probably the wrong thing to > do... A direct approach would probably use the webdriver API to autom

Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Danny Yoo
> After downloading pip, I tried to install it: > cd /Applications/pip-1.2.1 > install pip > > I got this strange message: > usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode] >[-o owner] file1 file2 >install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-

Re: [Tutor] operator order

2013-01-31 Thread Danny Yoo
On Thu, Jan 31, 2013 at 11:36 AM, heathen wrote: > why is this: > d *= 3 + 4 The gory details about how Python understands this expression can be found in: http://docs.python.org/3/reference/simple_stmts.html#augmented-assignment-statements Technically, "3 + 4" is the "expression lis

Re: [Tutor] Help- Regarding python

2013-02-04 Thread Danny Yoo
> How to do PCA on this data? if it is in array how to do that? and also how > to use princomp() in PCA? Principal component analysis, http://en.wikipedia.org/wiki/Principal_component_analysis may not be "built in". Do you know for sure that it is? According to this blog entry, you can do

Re: [Tutor] Code to open a website

2013-02-09 Thread Danny Yoo
On Sat, Feb 9, 2013 at 6:25 PM, mann kann wrote: > I used webbrowser and it worked via terminal, but the same code returns > AttrituteError: 'module' object has no attribute 'open' in komodo edit. > suggestions? here's the code: > > import webbrowser > webbrowser.open("http://youtube.com";) What

Re: [Tutor] help with inch to cms conversion .

2013-02-11 Thread Danny Yoo
On Mon, Feb 11, 2013 at 9:06 AM, Pravya Reddy wrote: > Can you please help me with the code. > > #!/usr/bin/env python > """ > inchtocm.py > > """ > > def Inchtocm(inches): > """Returns 2.54 * inches""" > return (2.54 * float(inches_number1)) I don't know if your curriculum talks about w

Re: [Tutor] Web programming question: Re: Tutor Digest, Vol 108, Issue 58

2013-02-16 Thread Danny Yoo
>> Hi, I signed up a while ago, but I didn't really understand anything. I >> have a basic question that maybe someone can help with. I'll like to >> integrate yelp data -- http://www.programmableweb.com/api/yelp -- onto >> google maps -- http://www.programmableweb.com/api/google-maps -- like >> ho

Re: [Tutor] Python API

2013-02-16 Thread Danny Yoo
On Sat, Feb 16, 2013 at 5:11 PM, Claira wrote: > I dont know how this mailing list thing works, first time on it, they > should have something that makes sense like quora.com > > Be aware that mailing lists have a pretty long history, at least in computing terms. You might be interested in readi

Re: [Tutor] following on

2013-02-19 Thread Danny Yoo
> Does this comment extend to C++? :-) > > Could the experts, please, recommend a beginner's book to learn the > principles of good programming? I'm partial to How to Design Programs as a beginner's textbook: http://www.ccs.neu.edu/home/matthias/HtDP2e/ because it emphasizes a systematic ap

Re: [Tutor] distance between cities matrix

2013-02-21 Thread Danny Yoo
> Consider the (20x20) array of numbers here(I wrote all of the numbers in > my program). Lets say this represents a matrix A of distances (in > kilometers) between cities. Note that A is symmetric A(i,j) = A(j,i) and all > its diagonal elements are zero. Suppose Vladimir from city i and Petra from

Re: [Tutor] Reversed dictionary returned by default

2013-03-01 Thread Danny Yoo
> Why is this happening, and how do I get it to work properly (returning > element 0 - n, versus n - 0)? Python dictionaries are unordered collections. When we iterate across them, we can not guarantee that we'll walk the elements in the order that we inserted them. The reason for that is becaus

Re: [Tutor] Need help with function coding.

2013-03-07 Thread Danny Yoo
> (a) Write a function which converts from gallons to cups2 Do you know how to write functions? Can you write a function that takes a number and returns twice that number, for example? Show us what you have seen already, and we may be able to start from there. The question you are asking does

Re: [Tutor] Need help with function coding.

2013-03-07 Thread Danny Yoo
On Thu, Mar 7, 2013 at 1:55 PM, akuma ukpo wrote: > i don't know how to write functions. so i guess that is where i'm stuck. i > was following a tutorial on my lab document but i still did not understand > what to do. i will attach the pdf and python files as well. I am CCing the rest of the Pyth

Re: [Tutor] Need help with function coding.

2013-03-07 Thread Danny Yoo
On Thu, Mar 7, 2013 at 2:36 PM, akuma ukpo wrote: > I am defining the function in one .py file and testing the function in > another .py file. > > this is my code for the test: > > def test_quantity_convert(self): > self.assertEqual(gallons_to_cups(0), 16) Good, thanks for showing us

Re: [Tutor] Bar Operator ??

2013-03-10 Thread Danny Yoo
> > It's a filter: > > https://docs.djangoproject.com/en/1.5/ref/templates/builtins/ And to be explicit about Mitya's point: it's technically not Python. It's part of Django's template language. If it were Python, it'd be interpreted as the "or" bitwise operator, http://docs.python.org/3/re

Re: [Tutor] Need help with python keyboard press/navigation commands

2013-03-11 Thread Danny Yoo
On Mon, Mar 11, 2013 at 8:59 PM, akuma ukpo wrote: > This is the problem > > Implement a function called get_direction which, on a particular character > , gives the > direction corresponding to that character. Do you know how to write a test case for this function? You had test cases for one o

Re: [Tutor] implementing rot 13 problems

2013-03-11 Thread Danny Yoo
The use of index() here to find the target place where the translation is going to occur is very fragile. Consider: we conceptually already should know where in the list we want the target to be, since we're walking across the characters in the list. We know that we're looking first at ls[0], tra

Re: [Tutor] implementing rot 13 problems

2013-03-12 Thread Danny Yoo
On Tue, Mar 12, 2013 at 9:00 AM, RJ Ewing wrote: > Thank you all for the help. I really appreciated the suggestions. Some of > the things you pointed out, I originally used, but started changing thing > when it wasn't working. I got it to work, but if you could let me know if > there is anything I

Re: [Tutor] implementing rot 13 problems

2013-03-12 Thread Danny Yoo
> ## > ## rot1: char -> char > ## Rotates a single character. > def rot1(char): > if char.isupper() or char.islower(): > test = 'M' if char.isupper() else 'm' > if char <= test: > return chr(ord(char) + 13) > else: > return chr(ord

Re: [Tutor] implementing rot 13 problems

2013-03-12 Thread Danny Yoo
> Also note that I've deliberately left alone a bug in rot1(), to make > it easier to show a flaw in the original code that you'll want to fix. Doh. Never mind. _I'm_ the one who introduced that regression. :( Sorry! Here's a corrected definition for rot1(): # de

Re: [Tutor] Modules

2013-03-27 Thread Danny Yoo
> I just started with Python and found a course named "Python programming" by > Jody S. Gunther. > My problem starts with the chapter "Introduction to Modules". > The first line in the program is: > from tkinter import * > and here I'm getting an error: > ImportError: No module named tkin

Re: [Tutor] Phyton script for fasta file (seek help)

2013-04-09 Thread Danny Yoo
Side note: I would strongly suggest using the biopython libraries for the basic parsing. FASTA parsing has been done and replicated so many times that it's almost a hazing ritual for the practicing bioinformatician. The biopython folks have written a parser, so perhaps you can reuse it. http

Re: [Tutor] Impossible Else as Exception

2013-04-09 Thread Danny Yoo
>> if condition is 1: >> do something with 1 >> elif condition is 2: >> do something with 2 >> else: # Impossible unless the code above is flawed. >> Raise Exception > > > > The above isn't a great example, because the sample code *is* flawed. > The short reason why it is flawed is t

Re: [Tutor] Phyton script for fasta file (seek help)

2013-04-10 Thread Danny Yoo
Hi Ali, Again, I recommend not reinventing a FASTA parser unless you really need something custom here. In this particular case, the function ReadFasta here is slow on large inputs. The culprit is the set of lines: if line[0]=='>': prevLine=line[1:] d

Re: [Tutor] Help on python

2013-04-15 Thread Danny Yoo
For example, see: http://nltk.org. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Sys.argv read parameters

2013-04-17 Thread Danny Yoo
What's the part that's "changing"? What's the part that stays the same? I would recommend thinking of this in terms of a function. Can you write a function that consumes a letter l and returns the string "This is ..." where "..." is the uppercased l? As an example of a simple function on string

Re: [Tutor] Sys.argv read parameters

2013-04-17 Thread Danny Yoo
Wait. If the solution that we're stopping at to use a hashtable here, that's not quite right. A good solution to this should be _much_ shorter, on the order of a one-liner. Hashtables are great, but they're not the answer to everything. If we're doing something like: a -> "This is A" b

Re: [Tutor] Sys.argv read parameters

2013-04-17 Thread Danny Yoo
Yup! Sorry about my tone for its stridency. But I just got concerned that the original poster seemed content about turning the chain of if statements into a table definition. To my mind, they're very closely related, data and control. I'm trying to push the OP to realizing that if they are doin

[Tutor] Fwd: Sys.argv read parameters

2013-04-17 Thread Danny Yoo
.argv read parameters To: Danny Yoo Hello Danny, The part that is changing is just the sys.argv[1] The vars will have always the same content. What I don't want is to have like 255 'ifs' if I have 255 vars. On Wed, Apr 17, 2013 at 5:03 PM, Danny Yoo wrote: > > What&#

Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danny Yoo
Ok, good. This is _much_ more realistic code, and demonstrates why seeing context is important. My suggestion to do it computationally is totally invalid here. :P There's a lot of variation here, due to the access paths through the JSON that you're walking. You're essentially defining a very l

Re: [Tutor] Fwd: Sys.argv read parameters

2013-04-18 Thread Danny Yoo
Followup: compare the previous interpreter code with this revision: https://gist.github.com/dyoo/5415464 and you'll see how it becomes easier now to add new command types into the system. ___ Tutor maillist - Tutor@python.org To unsubscribe or cha

Re: [Tutor] trouble installing library

2013-04-23 Thread Danny Yoo
According to the documentation in: http://www.virtualenv.org/en/latest/ and: https://pypi.python.org/pypi/virtualenv the "Installation" section in the documentation walks through what you need to do to install the software. Can you use Python's package managment system "pip" to handle

Re: [Tutor] why does this not work

2013-04-23 Thread Danny Yoo
Hi Roelof, On Tue, Apr 23, 2013 at 1:39 PM, Roelof Wobben wrote: > Im trying to learn python by a course at codeacademy. > > Now I have this code : > > def shut_down(s): > s = s.lower() > if s == "yes": > return "Shutting down..." > elif s == "no" : > return "Shutdown

Re: [Tutor] Runs in IDLE with F5, but not in Windows Command Prompt

2013-04-24 Thread Danny Yoo
On Wed, Apr 24, 2013 at 10:11 PM, boB Stepp wrote: > In my on again, off again studies of Python I am stumped on something > that ought to be trivial, but I am not seeing it. When I run this > program (only the part up to where the error occurs is shown): > > import random > > numberToGuess = ran

Re: [Tutor] Why do I not get the same results for these two functions when I pass 7 as an argument?

2013-05-03 Thread Danny Yoo
> elif days >= 3 < 7: This condition here, as well as: > if days >= 3 < 7: this condition here, looks very suspicious. Can you say what you trying to express here? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription

Re: [Tutor] range efficiency

2013-05-11 Thread Danny Yoo
On Fri, May 10, 2013 at 3:19 PM, Jim Mooney wrote: > If I'm using a variable-dependent range in a for loop, is Python smart > enough to figure the variable once so I don't have to hoist it up? Hi Jim, The gritty details say "yes": http://docs.python.org/2/reference/compound_stmts.html#the-

Re: [Tutor] when is a generator "smart?"

2013-06-01 Thread Danny Yoo
> > > print(list(uneven_squares(10,1))[2:10]) #slows as y gets bigger, then > dies > > You'll want to stick with sequence operations that do not force the entire generator's output. In this specific case, try itertools.islice. http://docs.python.org/2/library/itertools.html#itertools.islice __

Re: [Tutor] when is a generator "smart?"

2013-06-01 Thread Danny Yoo
> So how does one access a generator one element at a time? I thought > next would do that so I tried: > > print(next(uneven_squares(10,1000))) > print(next(uneven_squares(10,1000))) > print(next(uneven_squares(10,1000))) Each call to uneven_squares(10, 1000) creates a fresh iterator. You may wa

Re: [Tutor] Quick Question on String Compare

2013-06-01 Thread Danny Yoo
The standard sorting in Python depends on a comparison operator. A quick and easy comparison operator that Python uses for strings is lexicographic ordering: http://en.wikipedia.org/wiki/Lexicographical_order The quick and dirty rule is: dictionary order, with each character consistently tre

Re: [Tutor] Parse text with python

2013-10-17 Thread Danny Yoo
Do you have other domain-specific information about this text? Concretely: if you have another similar report, what parts will have to stay the same, and what parts might change? You want to make sure whatever you're using to anchor and search is based on something stable. Otherwise, your progra

Re: [Tutor] Parse text with python

2013-10-17 Thread Danny Yoo
> > > The part that always change is the , it can be 1 digit or 4 digits. > Example: 1. > The part that never changes is the 1700. > > You most likely need to be more specific with your pattern matching. Why should we expect no other numbers to be "1700"? I see several fields in the form tha

Re: [Tutor] Parse text with python

2013-10-17 Thread Danny Yoo
Yes. Concretely, I'm trying to see if it's appropriate to look at this: ### -LAL USER FILE- NAME UORD T/O O OXIT RXIT SMAX INUSE PCT --- - - - - --- J4IB

Re: [Tutor] Weird Python Error

2013-10-17 Thread Danny Yoo
Hi Zaid, Your YellowCar will have one once its reset() has been called. However, I don't see it in __init__(), so there might be a period of time where it won't have one. I haven't traced through possible code paths where this happens, but I suspect one of them may. One example may be: c =

Re: [Tutor] Reading CSV files in Pandas

2013-10-21 Thread Danny Yoo
On Sat, Oct 19, 2013 at 7:29 AM, Manish Tripathi wrote: > > I am trying to import a csv file in Pandas but it throws an error. The format of the data when opened in notepad++ is as follows with first row being column names: > > "End Customer Organization ID,End Customer Organization Name,End Custo

Re: [Tutor] Reading CSV files in Pandas

2013-10-21 Thread Danny Yoo
> > * Where is this data coming from? > * Who or what is generating this file? Just to be more specific about this: I have a very strong suspicion that whatever is generating the input that you're trying to read is doing something ad-hoc with regards to CSV file format. Knowing what generated th

Re: [Tutor] Reading CSV files in Pandas

2013-10-21 Thread Danny Yoo
On Mon, Oct 21, 2013 at 11:57 AM, Manish Tripathi wrote: > It's pipeline data so must have been generated through Siebel and sent as > excel csv. > > I am assuming that you are talking about "Siebel Analytics", some kind of analysis software from Oracle: http://en.wikipedia.org/wiki/Siebel_Sy

Re: [Tutor] [OT] Programming practice was: Re: string list in alphabetical!

2013-10-21 Thread Danny Yoo
> > > I agree. I've recently started coaching the son of a friend in computing > for his new school (he is effectively a year behind > his new classmates). They use VB6 but at a level I can cope with! :-) > > The interesting thing however is that the schools have not taught > any kind of approach t

Re: [Tutor] Want to keep to two decimal places for currency

2013-10-23 Thread Danny Yoo
On Wed, Oct 23, 2013 at 4:13 PM, Alan Gauld wrote: > On 23/10/13 22:39, Shelby Martin wrote: > >> I've looked online but I'm confused - I need to keep it so that the >> following program limits the output to two decimal places since it deals >> in currency. >> > > Its generally a bad idea to use f

Re: [Tutor] Python and memory allocation

2013-10-24 Thread Danny Yoo
> And does python being an interpreted language have to do anything with this? I have to interrupt: you mean to say: "And does the C implementation of Python (CPython) have to do anything with this?". There are several implementations of Python out there. Not all of them use an interpreter in th

Re: [Tutor] Want to keep to two decimal places for currency

2013-10-24 Thread Danny Yoo
On Thu, Oct 24, 2013 at 9:37 AM, Shelby Martin wrote: > Thank you for your replies. I suspect the solution is a bit more advanced > than where I'm at now, which is chapter 2 of a beginner's book. > Probably because talking about the gory details would completely derail the conversation, as I did.

Re: [Tutor] UnicodeDecodeError while parsing a .csv file.

2013-10-28 Thread Danny Yoo
Hi Sm, Note: if possible, I would strongly suggest reusing csv.reader rather than reinvent this. It comes in Python's Standard Library: http://docs.python.org/3/library/csv.html#module-csv ​ --- Anyway, to your question. Do you know what is the encoding of your input file? (And if you don

Re: [Tutor] Dictionary from a text file

2013-10-31 Thread Danny Yoo
> > > Note: in* 'call' : Update* ,Update it is a function defined in my python > script. My dictionary is too large so i taught rather than using directly > in python program I save it in a text file and when needed i assign it to > dictionary object . How can i assign this text file to dictionary

Re: [Tutor] Geometric sequence

2013-10-31 Thread Danny Yoo
As an aside: It shouldn't be too bad to write a "generator" for the geometric series, so that we can pick out the terms on-demand. # >>> def geometric(base): ... x = 1 ... while True: ... yield x ... x *= base ... >>> twos = geometric(2)

Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Danny Yoo
On Mon, Nov 4, 2013 at 9:41 AM, Amal Thomas wrote: > @Steven: Thank you...My input data is basically AUGC and newlines... I > would like to know about bytearray technique. Please suggest me some links > or reference.. I will go through the profiler and check whether the code > maintains linearity

Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Danny Yoo
> > > > Also as I have mentioned I cant afford to run my code using 4-5 times > memory. > > Total resource available in my server is about 180 GB memory (approx 64 > GB RAM + 128GB swap). > > OK, There is a huge difference between having 100G of RAM and having > 64G+128G swap. > swap is basically d

Re: [Tutor] Load Entire File into memory

2013-11-04 Thread Danny Yoo
> > You _must_ avoid swap at all costs here. You may not understand the > point, so a little more explanation: touching swap is several orders of > magnitude more expensive than anything else you are doing in your program. > > CPU operations are on the order of nanoseconds. (10^-9) > > Dis

Re: [Tutor] String representation of NULL (non type) values

2013-11-05 Thread Danny Yoo
> > > from a SQLite database I get a value by SELECT s from... which normaly is > a string, but can be the NULL value, wich means it is not defined. To put > the value into a form (made by QT) I need a string representation. > > str(s) gives either the string itself (which is good) or "None" (which

Re: [Tutor] Finding a nearest perfect cube

2013-11-07 Thread Danny Yoo
> > > If i input a number, i should get a perfect cube nearest to it. > For eg: if > input=4, output=8 > input=8, output=27 > and so on > Let's consider those examples. Pretend you were given: input = 4 and the description of the problem. Forget computers for a brief moment. What woul

Re: [Tutor] sequence of elements problem

2013-11-08 Thread Danny Yoo
On Fri, Nov 8, 2013 at 4:54 AM, donsuni wrote: > Hi, I have a problem in python which is kind of tricky. > > if i give a sequence of numbers, i should get another sequence of numbers > such that the the elements exceeds previous element in the list. For eg > Have you written any other functions

Re: [Tutor] ideas?

2013-11-18 Thread Danny Yoo
For reference, here are the documentation pages for ord() and chr(): http://docs.python.org/3/library/functions.html?highlight=chr#ord http://docs.python.org/3/library/functions.html?highlight=chr#chr On Mon, Nov 18, 2013 at 3:01 AM, Alan Gauld wrote: > On 18/11/13 03:27, Byron Ruffin

Re: [Tutor] Two subsequent for loops in one function

2013-11-22 Thread Danny Yoo
I agree with Peter Otten. I want to try restating what he said to try to emphasize what I think is the key point. One basic skill that you learn as a programmer is how to handle nesting. One strategy is to give things names. This can have benefits: 1. The name itself might make the code ea

Re: [Tutor] Issue w/ while loops

2013-11-22 Thread Danny Yoo
> Ok, got you! > > print("TIME TRACKING") > > while True: > hours_worked = input("How many hours did you work today? ") > try: > hours_worked = float(hours_worked) > break > except ValueError: > print ("Invalid input") > if hours_worked < 24: > print("You mus

<    11   12   13   14   15   16   17   18   19   20   >