3,386 Posted Topics
Re: I posted simple snippet of basic search for root value in **Code Snippets** | |
Re: In my Ruby (Ruby 1.9.3 under WindowsXP), it does not show the ord by indexing character, but you need to do: (Array('A'..'Z')|Array('a'..'z')|Array('0'..'9')).each do |letter| puts "#{letter}\t\t#{letter.ord}" end | |
Here improved example based on MITx course of using the bisection method for root finding. | |
Re: It would be usefull to know what you tried and the test which failed. I assume you are basically wanting memoize a property to an instance of the class. There would be many ways I think, some do not work in class without \__dict__ https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/utils.py#L30 | |
Re: Some work on it to dictionaries and changing the base currency by function updating the **mutable** dict. Also changed the rates to floats to be more usefull. '''currency.py open a currency rate URL for reading tested with Python27 and Python32/33 based on vegaseat's code ''' import pprint try: # Python2 … | |
Re: value function does not exist, and it does not make sense to indent the 25-27 inside the definition of a class. You are obviusly not understanding what class is about please read up little more and read some code from code snippets archive like http://www.daniweb.com/software-development/python/code/431887/the-employee-class-record-revisited Here something closer to your … | |
Re: For full factorization sieve you can store the smallest prime factor for each number and then you have all numbers factored only by traversing through the sieve. | |
Re: target = '4.0000000E+00' with open('test.txt') as infile, open('file_08.txt', 'w') as outfile: for line in infile: if not line.startswith('BNBCD ') or target not in line: outfile.write(line) | |
Re: What are you trying to do7 Can you state your logic? i think writing some functions would help to clean the code and make it readable. | |
Re: I agree with wooeee's suggestions. However you should not use clear_scores function but do # clear the old scores scores[:] = [] or #make new empty list for scores scores = [] | |
Re: You must show some effort first yourself. | |
Re: I do not know exactly what you are after, but generally Compute Science needs more like introduced in book **Concrete Mathematics** by *Graham, Knuth and Patashnik* I have not been able to read it yet much but I have it, and the auctority of Knuth can not be denied. | |
Re: Alternatively: line_count = 3 with open('original.txt', 'a') as orange: orange.writelines(('%s\n' % raw_input("Enter message %i:" % ind)) for ind in range(1, 1+line_count)) | |
Re: I would sqrt cast to long integer and use exact equality check of it's square against the integer number. | |
Re: You do not do that. You have design fault. | |
Re: Type `import this` at Python prompt ;) | |
Re: usually you would add separator like _ between parts of name or use fixed number of digits. Otherwise you ned to code parsing function, use regular expression to find numbers (`re.findall(r'\d+', filename)`) Also iterating in opposite direction would help. | |
Re: What kind of button is this? Usually commands are functions, not strings. | |
Re: divmod function might prove helpfull as alternative (or integer division and %) | |
Re: Use split method `line.split('|')` and collect the information. Is the information sorted on the third field like your sample looks like? If so, you can just add up the points, otherwise use a dictionary. Do not forget to change the string of digits to integer. | |
Re: >Jython is written in Java, yes, and PyPy is writen in Python (or limited subset RPython), but IronPython is .Net friendly implementation, written in C# (thanks, Gribouillis!). | |
Re: Line 60 does not make sense as it is not in a if statement. if of line 39 ends of course line 53 as indentation is outdented at line 54 to main program level. | |
Re: Combination of lines 7 and 8 does not make sense as condition would allways be True as the word comes through iteration of line (and is a character not word). Are you allowed built in find method? | |
Details and download from http://python.org/download/releases/3.3.0/#download | |
Re: I do not understand so well but here version with everything I did not understand cut out def findobj(searchTxt,items): """ This function will help you find an object or an item from list of items passed to it. """ for each in items: if each == searchTxt: print each #and … | |
Re: Your words about not paying attention to too small probability sounds like famous last words of programmer ;) :( | |
Re: My short course of percent calculation: 1. 1 =100% <=> 1% = 0.01 2. Percent calculation does not exist, it is just multiplication. Everything else follows from these two facts. | |
| |
Re: The code could be massaged for example like this: from math import * class Triangle(object): """Checks if given sides can make a Triangle then shows the Angles.""" def __init__(self, a, b, c): self.__check_triangle(a,b,c) self.a = a self.b = b self.c = c self.calculate_angles() def __check_triangle(self,a,b,c): """Checks if given sides can … | |
Thank you for voting for the code snippet competition! pyTony | |
Re: Here Dani's tutorial from tutorials section (tab) of the forum: http://www.daniweb.com/software-development/computer-science/tutorials/1727/an-introduction-to-algorithms | |
Re: I do not think you should include 0 as possible value to your triplets. And of course there is more efficient methods than brute force. >>>print(list((a,b,c) for a,b,c in itertools.product(range(1, 100), repeat=3) if a<=b<=c and a**2 + b**2 == c**2)) [(3, 4, 5), (5, 12, 13), (6, 8, 10), (7, … | |
Re: Your code is actually very nice for beginner! I would slightly rearrange the calling the functions and do itertools.takewhile from sorted wordlist to rechecking whole word list. from string import punctuation as punc from itertools import takewhile def find_longest(text): """ find length of longest word and what are those words … | |
Re: You must start from simple functioning program and build on it, here little advanced # make code work in both Python2 and Python3 from __future__ import print_function, division try: input = raw_input except: #Using Python3 pass conversion = input("Enter 'F' to convert to Fahrenheit, 'C' to convert to Celsius: ").upper() … | |
Re: Do show effort solving your problem and ask about specific problem in your code. | |
Re: You can use set and & for intersection: d1 = """ 12313 : 23546 12313 23214 32465 """ d2 = """ 13132 : 23546 12323 32125 32125 32121 """ ds1 = set(line[8:].strip() for line in d1.splitlines() if line) ds2 = set(line[8:].strip() for line in d2.splitlines() if line) print ds1 & … | |
Re: Good luck from me also, at least you allready got the assignement statement, maybe you could move on to loops for a challenge, maybe those i,j,k variables is hint from your teacher for that? And you could only include modules which are standard and used in your code (and no … | |
Re: Duplicate finding usually is simplest by just doing sorted copy and removing the duplicates (sequentiailly) from the ordered data. If you would use genetic programming, you would make it to find a algorithm better than this. | |
Re: Basically you should keep movement state in one separate variable and only touch it when movement affecting keys have been pressed. So you move not only when key is pressed but every tick and key pushed conditions only change the movement variable. | |
Re: I would think you would be better off to add functionality to inbox.Inbox by inheriting, I do not see what object the DelSMS corresponds with. | |
Re: It is, I think, necessary why would somebody to consider this kind of complication to use. One reason is that the importing of large modules takes considerable time, so it would be nice to delay the import itself to time when the function from module is actually called, so execution … | |
Re: There was accidental mixup in variable names in woooee's answer. def checkAll(char): wins_list = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]] for first, second, third in wins_list: if check_line(ch, first, second, third): return True | |
Re: Your code seems to run OK, not that output would make much sense for me... | |
The forum does not seem to accept url with () http://www.daniweb.com/software-development/python/threads/434692/python-launcher-doesnt-work#post1866059 | |
Re: What kind of she bang line you got? http://www.google.com/search?q=python+shebang+mac | |
Re: Did you use Google 'py4A bluetooth' that finds for example this http://www.slideshare.net/george_goh/pycon2011-android-programmingusingpython see page 33 example. | |
Re: This? http://en.wikipedia.org/wiki/Formal_concept_analysis |
The End.