761 Posted Topics
Re: It sounds to me as if you want to either recreate something like Matlab or something like a spread sheet. As an exercise, this seems very large. As a tool, there are probably freely available ones already in existence. Look here: [url]http://www.CJFearnley.com/higher.math.and.open.source.pdf[/url] (see my signature). | |
Re: @henryford you are getting desperate, which always makes bad code. Please take a minute to breathe, get a drink of water or caffienated, not booze :) and walk around the room. I'll wait. OK. The right way to do this is to break off a piece and do just the … | |
Re: dateline 2020: "Computer? Isn't that something my dad used to access data or something? I just use my phone for all that stuff." | |
Re: [CODE]for k,v in dictionary.items(): dictionary[k] = v[0] [/CODE] [url]http://docs.python.org/library/stdtypes.html#mapping-types-dict[/url] You can use dictionary.iteritems() if you prefer, but beware "[B][I]Using iteritems() while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries.[/I][/B]". Fortunately, we aren't adding or removing here, just changing the value … | |
Re: Do you need to deal with the possibility that the data can start with zero(s)? Generally, RLE has to deal with more than two tokens, so it uses a dictionary header, and outputs both the dictionary index and the repetition for each run of "same token". So, your example would … | |
Re: "[I]i still can't get it to restart the program fully without it showing previous results[/I]" Do you mean that you want the screen to erase the prior input and calculated results? That is tricky if you do it by clearing the screen, but you can do something very simple: At … | |
Re: [LIST] [*]By now you should have a lot of ideas about what the world needs from the profession you are learning. Do one of those things. [*]Ask your favorite prof for suggestions [*]What [B]else[/B] do you care about in your life, other than school subjects. Do a project about that. … | |
Re: Don't you have the logic for the change backward? Look at lines 34 and 35 and think carefully (by the way, why do you need variable[icode]temp[/icode]? Related: You can always instrument your logic blocks with a print statement that shows where you are. When in an infinite loop, hit Ctrl-C … | |
Re: I notice that lines 1 through 5 are:[LIST] [*]useless [*]never called (fortunately) [/LIST]It [I]almost[/I] looks as if you are trying to make an Employee class (which is not a bad idea) but don't understand how to do it. ([I]almost[/I] because I don't see how the[ICODE]hWork[/ICODE]fits in.) Here's how:[CODE]class Employee: def … | |
Re: show some code please... don't forget to use the Code tags. | |
Re: Why is sufficient clean water difficult in other tropical islands if this technique is truly a simple inexpensive and adequate solution? I suspect that the answer is in two parts: [LIST=1] [*]I think this technique provides only an insufficient amount of water for the effort and cost. (How often do … | |
Re: You will want something like this (I have not double checked syntax, have not mentioned the obvious foreign keys, and didn't note any indexes):[CODE]create table project ( id unsigned not null auto_increment, when date, /* so you can have the same title at the next fair */ title varchar(128) not … | |
Re: lets start easy: [CODE]lines = [] with open('test.txt', 'r') as f: for x in f: if x.strip() # lose empty lines lines.append(x.strip()) for line in lines: print(line) [/CODE]This just eliminates the blank lines, then prints out the remainder. Of course you will want to do some more work. You will … | |
Re: First: Please wrap your code in Code tags. The easy way is to press the Code button on the toolbar, then paste your code; or you can paste first, highlight your code and then press. The result: - Your parentheses and semi-colons don't interact to make smilies - Your indentation … | |
Re: [CODE]import re #Imports the Regular Expression Library f = open('randomcharacters.txt') #Opens "randomcharacters.txt" from same directory as the script lineToSearch = "" for line in f: lineToSearch += line #Goes through all the lines in the data one by one pingFinderPattern = re.compile('time=([0-9.]+) ms') Pattern1 = re.search('time=([0-9.]+) ms', line) Pattern1 = … | |
Re: We must clearly distinguish [I]binary tree[/I] in which there is no particular order and [I]binary search tree[/I] in which and a depth-first right to left traversal gives a fully sorted list. @bleedi used 'search' in the title, but not in the body. Same as @firstPerson, I'm not sure if the … | |
Re: Here's the bad news (search for "Symlinks") [url]http://www.sveinbjorn.org/cljg2macosx[/url] | |
Re: Here's another bit of code that will give you part of the solution:[CODE]import os dirpath = '/the/directory/path' # or maybe r'D:\the\directory\path' for item in os.listdir(dirpath): p = os.path.join(dirpath,item) desc = 'file' if os.path.isdir(p): desc = 'folder' if os.path.islink(p): desc += ' (link)' print("I found a %s: %s"%(desc,p)) [/CODE] [url]http://docs.python.org/library/os.html#os.listdir[/url] and … | |
Re: So your main program is a loop that accepts user input using either `raw_input` or if Python 3, `input`. Assuming Python 2.x, then it looks like: keep_asking = True prompt = 'Choose from “help”, “lookup”, “enter”, “remove”, and “quit”: ' while keep_asking: user_input = raw_input(prompt) # do something with user_input … | |
A nice short interview/article [URL="http://www.wired.com/thisdayintech/2010/10/1014cplusplus-released"]here[/URL] | |
Re: The more pythonic way to do multiple if/elif/elif/elif/.../else branching is to have a dictionary that maps the value of the tested variables to a function.[CODE]# case statement in python def a(): pass def b(): pass def default_func(): pass dispatcher{'a':a,'b':b} # mimic if 'a' elif 'b' else if key not in … | |
Re: How is this a MySql issue? Yes, I would just go ahead and replace the HTML/XML special characters. There are utilities available that can do this 'semi-automatically' for you. | |
Re: for example, because your title was 'swap' items in a list:[CODE]a_list = [1,2,4,3] print(a_list) tmp = a_list[2] a_list[2] = a_list[3] a_list[3] = tmp print(a_list)[/CODE]Of course for this particular example you could also have just said [icode]a_list.sort()[/icode] to get the same effect as lines 3,4,5 | |
Re: 1. Please begin to use the (CODE) button to post your code: Either press the button first, then paste between the (CODE) and (/CODE) tags, or paste first, highlight and then press the button. This results in properly indented, keyword-colored code with line numbers. All good things. 2. It appears … | |
Re: - Please use the (CODE) button to wrap your code (You may either press it first then paste between the (snip) and (snip) tags, or paste first then highlight and press the CODE-button. This gives code coloring, line numbers, and maintains indentation: All good things. - It is generally considered … | |
Re: Sure you can. The code looks something like this (done in a hurry):[CODE]import math s = (1,2,3) t = (5,5,5) x0 = (s[0]-t[0])**2 x1 = (s[1]-t[1])**2 x2 = (s[2]-t[2])**2 print math.sqrt(x0+x1+x2)[/CODE] Hope this helps | |
Re: Two things: 1. You should use the (CODE) button around your code: It saves indentation, does keyword coloring, adds line numbers. All good things 2. What is this line doing? `words = line.split(p)`. I don't see any declaration of the variable **line**... and suspect you have cut and pasted something … | |
Re: For one thing, I don't understand your [iCODE]linear_merge[/iCODE]. Extend handles a whole list, not a single item at a time. I would do[CODE]def merge_to_new_list(list1,list2): ret = [] ret.extend(list1) ret.extend(list2) return ret[/CODE] Then, I do not understand your last question: [I][B]how to access those same points in merged list (cuz I … | |
Re: Since you know all the questions in advance, you can create a single table with one column per answer (some answers must be nullable so that the user can choose options that would not be consistent (for instance, if you choose to build a Linux box, then you cannot choose … | |
Re: C++ attempts to call the default constructor for each element of an array. Profile doesn't have a default constructor (only one that takes two arguments). Either provide that default constructor or make [iCODE]myarray[/iCODE] hold pointers to Profile instances. C++ will provide a default constructor for a class only if you … | |
Re: According to my reading, you cannot ask in a portable way for the amount of available or in-use heap. The best you can do in platform-independent C, which "best" is not really much, is attempt to (m)alloc some memory, and note if you get back a non-null pointer. C does … | |
Re: I would think about how to do this for a given line, then call it for each size in turn. For simplicity, lets do it without indenting correctly first: [CODE]function triline() { item=1 # keep track of what to 'store' next linesofar="" # keep track of what is already stored … | |
Re: You want to use the [URL="http://docs.python.org/library/re.html"]re nodule[/URL]. There are examples of use as well as a full reference. Be aware of the difference between the [B]search[/B] and the [B]match[/B] methods. | |
Re: I prefer to use setdefault to avoid branching in the python code (I assume that the builtin type is more efficient at such things)[CODE]mydict = {} for line in file: mydesc,myword = [w.strip() for w in line.split(',')] mydict.setdefault(myword,[]) # after this, we know mydict[myword] is a list mydict[myword].append(mydesc)[/CODE]If your file … | |
Re: I am confused. [LIST] [*]From whom are you hiding the functions (and such)? [*]What do you mean by "when they happen"? [*]Can you give a longer example showing what you (don't) want to happen? [/LIST] | |
Re: It skips the first line because you aren't [I]split[/I]ing it. Try this (which I very slightly modified from @jcao219's post)[CODE]with open("scores.dat") as fileIn: # with statements are cool: http://effbot.org/zone/python-with-statement.htm for line in fileIn: # this loops over every line in the file if line: # this line skips empty lines … | |
Re: "[B][I][I will] have to report the false positives and false negative[/I][/B]" It is very very odd to want a program both to do some work and also report on when it failed to do it correctly. It is quite difficult to validate XML or any other markup language: You have … | |
Re: Well, that is indeed a monster... Here are some things to think about: [LIST] [*]function [icode]rollDice[/icode] can be simplified two ways: [LIST=1] [*]you can just call [icode]random.randint(1,6)[/icode] directly inside the square brackets. No need for the multiple appends [*]you can just [icode]print(roll)[/icode] for a sufficiently pretty output, though yours works. … | |
Re: I used Eclipse very happily when I was coding a lot in Java. Lots of nice short cuts, useful plugins (and not too hard to add or modify them), an OK way to handle version control stuff, acceptable screen layout with reasonable options (cannot get a perfect screen layout because … | |
Re: I am guessing that your background is either not programming, or you are used to a nice IDE. Python has some freely available IDEs, but in honesty, I don't know what they are: I just use Emacs (and I do it on a Mac). I think you can probably make … | |
Re: There is a brief but clear article here: [url]http://effbot.org/zone/unicode-objects.htm[/url]. I also liked this one [url]http://diveintopython3.org/strings.html#one-ring-to-rule-them-all;[/url] ... from which I have stolen this one important insight: [B][U][COLOR="Red"]Bytes are not characters; bytes are bytes. Characters are an abstraction.[/COLOR][/U][/B] For clarity of thinking, you also need to be [B][I]very[/I][/B] aware that "Unicode" [B]is … | |
Re: @wooee is keeping the problem you have in (most recent) line 10, which will return just a single character as the second part of the return duple. The issue is whether class Sentence is more about the full sentence as a string, or more about the list of words in … | |
Re: Look here for Python documentation: [url]http://docs.python.org/[/url] And here for various parsers: [url]http://docs.python.org/library/markup.html[/url] | |
Re: @firstPerson: Disagree that you need to greedy calculate the various things about the circle: If the program never uses that information, it was a waste of space and CPU. Minimize... Of course, once the program uses it, it might be cached to avoid re-calculate (or not: A simple multiply is … | |
Re: Requirement analysis: Use brain as primary tool. Use pencil/paper for sketching, editor for keeping notes, spread sheet for costing; more specialized tools for special tasks. Negotiation: Use ears/eyes, brain, mouth/email in that order. | |
Re: That looks right to me, though the spacing makes it a little difficult to look at. | |
Re: Answer second post first: You can add an index without affecting (except efficiency) your queries. However if the table is very big, adding an index can take significant tie and space (I've seen it take some hours for a table with millions of rows, partitioned by time_stamp into many sub-tables... … | |
Re: Think about this: What is the address of [icode]array[0][0][/icode]? Another way to get enough time to measure is to do the smaller amount of work multiple times:[CODE]for(int i = 0; i < 100; ++i) { //do the work }[/CODE] Yet another thought: The optimizer may be able to optimize away … | |
Re: Let me add an idea. If you are going to use "LIKE" then you need to decide what things are wild cards (all vowels?). There may be a better way: A really helpful search technique would look for homophone matches as well as more accurate spellings . [URL="http://creativyst.com/Doc/Articles/SoundEx1/SoundEx1.htm"]Soundex[/URL] is an … | |
Re: You are going to have trouble here, too: userInput=raw_input('Enter a rating 0-5 for ' + movie[n] + '\n') if 0<=userInput<=5: The return from raw_input is a string, not an integer. You need the line to be `userInput=int(raw_input('Enter a rating 0-5 for ' + movie[n] + '\n'))` P.S. I don't know … |
The End.