3,386 Posted Topics
Re: ..when you start to write an algorithm for it if people are asking where you are going for holidays mumbling: hhmhh.. NP-hard.... | |
Re: Interesting syntax point, however the: [CODE](5).imag[/CODE] does work as does [CODE]int(5).imag[/CODE] I thought it is because the constant could be floating point number, and it makes sense that: [CODE]5.4.imag[/CODE] is not valid syntax, but actually it is accepted by interpreter. | |
As [URL="http://www.daniweb.com/software-development/c/threads/377568/1625821#post1625821"]Goddess Narues' C code in C forum[/URL] was over my head and her critique of simplistic solution maybe overflowing the integer range was valid in C, I worked out a recursive solution more suitable to my brain in my preferable language. Maybe one day I put in C, now … | |
Re: From value/g and g/cm3 calculate value/cm3 and decide based on this. Can he take any amount he likes or must he take all the pile of powder? | |
Re: Difficult to test without the pictures (you can attach them from Advanced Editor) | |
Re: This is my correction för dig for previous version you posted: [CODE]count = 0 # in later versions (2.72, 3.21) you can write: #with open('test.txt') as f, open('new.txt', 'w') as f_out: with open('test.txt') as f: with open('new.txt', 'w') as f_out: for line in f: while 'value' in line: count += … | |
Re: You can save it in same directory as your code, or you can use os.path.expanduser('~') as base of your data directories, like os.path.expanduser('~/data') | |
![]() | Re: Of course we have object say our master, and as Buttons are in global scope they need not be saved as they will not be garbage collected. [CODE]from functools import partial from Tkinter import * master = Tk() def on_press(value): master.d = value master.title(str(master.d)) for value in (10, 20, 30): … |
Re: [CODE]import wx class bucky(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, "Testing erea", size=(280,400)) panel = wx.Panel(self) food = wx.Button(panel,label='Food',pos=(10,10),size=(80,40)) pets = wx.Button(panel, label='Pets', pos=(100,10), size=(80,40)) self.Bind(wx.EVT_BUTTON, self.food, food ) def food(self, event): wx.StaticText(self, -1, 'Bacon, apples, tuna', (40,300)) self.Bind(wx.EVT_CLOSE,self.closewindow) def closewindow(self,event): self.Destroy() if __name__=='__main__': app=wx.PySimpleApp() frame=bucky(parent=None,id=-1) frame.Show() app.MainLoop() [/CODE] | |
Re: %f and float n does not look integer to me, like your prompt and algorithm suggests. | |
| |
Re: Not using looping could mean recursion or goto label, depending on definition. | |
Re: Lambda is usefull, sometimes it is nicer to replace it with proper function or use functools.partial instead. Say if you wanted to sort strings so that the sort is case insensitive and words starting with x come first instead of normal place (but x inside the string behave normally) [CODE]def … ![]() | |
Re: I do not get the need of sorted etc from the requirement, I read it like: [CODE]# A. match_ends # Given a list of strings, return the count of the number of # strings where the string length is 2 or more and the first # and last chars of … | |
Re: Sounds like trying run Python2 code in Python3, did you try to run 2to3.py script for the code? Try changing strings to bytes: b'' | |
Re: Looks that you are trying to do something super complicated to confuse yourself and maybe others that read your code. What is ultimate purpose of this metaprogramming? I don't think it serves any proper purpose. Generally if somebody wants to do this kind of trickery, they should be using sequence … | |
Re: I think you should pass the root window to Toplevel: [CODE]from Tkinter import * root = Tk() win2 = Toplevel(root) [/CODE] | |
Re: There is many ways, if the text is big, usually you would build dictionary with letter pairs as keys (for example for random text generation). Here is one example of more advanced way of doing it by list comprehension: [CODE]>>> def follow_char(big, small): return [c for n, c in enumerate(big[len(small):], … | |
Re: Sorry, but I do not see the connection of your code and task as I understand it: [CODE]def one_count(n): return str(n).count('1') def sum_of_ones(total): return sum(one_count(page) for page in range(1,1+total)) print(sum_of_ones(10)) print(sum_of_ones(55)) """ Output: 2 16 """[/code] | |
Re: I would use moving maximums to k array or keeping sorted k length array built from the long array. Or I would adapt quicksort to take pivots from correct side. | |
Re: Something like this gets you data from file and transposed data in each frame in dictionary: [CODE]from pprint import pprint import itertools as it def yield_info(fn = 'info.txt'): with open(fn) as info: for line in info: if line.startswith('frame:'): # read in frame number current = int(line.rsplit(': ')[-1]) if line.startswith('('): yield … | |
Re: If you have access to shell and Python, functionality of CRON is of course simple to do in Python, as also sending the emails from your home computer in patches (say sending loop with 3600 s time.sleep() every hundredth mails). Are those letters exactly same, or they have differing contents. … | |
What does this print statement produce and why? Learned it today, I still must be a newbie. [CODE]print('%0*d' % (3, 7))[/CODE] | |
Re: As I see from your prompt, you are working in Linux (et al). Usually python 3 installs also with name python3 in /usr/bin. Easy way to check it is to try to run it from terminal window or type python<tab> and see which completion alternatives are available. Then you can … | |
![]() | Re: [CODE]>>> b = a[a[:,2]==1] >>> b array([[ 0. , 0.01, 1. ], [ 1. , 0.02, 1. ]]) >>> [/CODE] |
Re: That is really dependent of the nature of function applied and if there is overlap with previous answers and recursive function, you can sometimes reverse it to build dynamic programming solution or if it is difficult use memoized recursive function. I have recently done some subrange sums, but not in … | |
Re: Here is one simple solution, but it puts comma after the last value also, if that is problem you should print all but last in the loop and print separately the last one. There is also more advanced methods of formatting, but looking the style of your code thought this … | |
Re: Code tags are generally good idea of getting response: [CODE]#!/usr/bin/env python from gasp import * # import everything from the gasp library begin_graphics(title="Houses At Night", background=color.BLACK) # open the graphics canvas def draw_house(x, y): Box((20, 20), 100, 100, filled=True, color=color.BLUE) # the house Box((55, 20), 30, 50, filled=True, color=color.GREEN) # … | |
Re: I got interested in Scala, even Python is my main language, as it is compiled and more flexible than Java, but was taken aback by [URL="http://neopythonic.blogspot.com/2008/11/scala.html"]analysis of Python Benevolent-Dictator-for-life Guido van Rossum[/URL]. | |
Re: Wikipedia [URL="http://en.wikipedia.org/wiki/Function_object#In_Python"]function object Python section[/URL] is using simple object with __call__ and __init__ for start value as Accumulator. Could you give example of benefit of your approach disallowing the __init__? | |
Re: I do not understand this globbing before you are even inside walk loop. Maybe you could check out my code for finding files of given list of extensions, those containing one of the list of texts: [url]http://www.daniweb.com/software-development/python/code/316585[/url] There I am using the option of running function for all files instead … | |
Re: If you are running under Linux, you can use: [url]http://www.daniweb.com/software-development/python/code/323792[/url] This looks also promising: [url]http://pywebgraph.sourceforge.net/[/url] | |
Re: I do not see problem for that: [CODE]>>> a='13.33' >>> a=float(a) >>> a 13.33 >>> print(a-13.33) 0.0 >>> [/CODE] | |
Re: Looks like C++ for me. Not "related to the C language as per the ANSI C standard." at least. | |
Re: I do not understand your problem, post runnable code including the include statements and function definitions. You have not User_select defined. It is not safe to use gets, as you can not specify the maximum amount of characters you have allocated: [url]http://www.daniweb.com/software-development/c/tutorials/45806[/url] | |
Re: Check this: [url]http://www.merriam-webster.com/dictionary/doubt?show=0&t=1312659545[/url] You need atomic test and set. I do not know what you mean with default value of mutex. Usually I would think critical block is not locked at beginning, meaning value 0. | |
Inspired by Computer Science forum post, I did this code. I prepared it Shedskin compatible, and it runs quite nicely indeed. Even interpreted the algorithm is faster than full sort. Here interpreted test for the module, shedskinning this test would show better time for sort solution. Python version has benefit … | |
Re: For example with [URL="http://lxml.de/"]lxml module[/URL] or standard modules: [url]http://wiki.python.org/moin/PythonXml[/url] (ElementTree) | |
Re: 'when running my IDE' -> usually bad idea to run tests (only) from IDE Configure a text editor (like context) to launch real Python session or use command line to run the code, or insert at end input statement and double click the file (usually graphics stuff enters in mainloop … | |
Re: Logical for me is: All element between limits are solutions, and then you can consider those subsequences 2..j-i (or going over R for sum) length where that element is value with smallest index. Does not look O(n^2) for me. | |
Re: I do not understand your format: [CODE]>>> AB={'Joshua' : 'Joshua: ''Email: sho0uk0m0o@gmail.com Phone: (802) 3-5-2206', 'Ashley' : 'Ashley: ''Email: a000@gmail.com Phone: (802) 820-0000',} >>> AB {'Joshua': 'Joshua: Email: sho0uk0m0o@gmail.com Phone: (802) 3-5-2206', 'Ashley': 'Ashley: Email: a000@gmail.com Phone: (802) 820-0000'} >>> [/CODE] | |
Re: [CODE]>>> def are_same(a, b): return set(a) == set(b) and len(a) == len(b) >>> are_same(("foo", "bar", "baz"), ("baz", "foo", "bar", "baz")) False >>> are_same(("foo", "baz", "bar", "baz"), ("baz", "foo", "bar", "baz")) True >>> [/CODE] For hashability use frozenset or tuple of sorted values. BTW other formulation from this is: [CODE]>>> def … | |
Re: Sieve, but store odd values between limits instead of 3...limit. Only you do unoptimal taking out of multiples if you take out multiples of 6 +- 1. Alternativesly prepare next_prime function which uses reasonable isprime with 2, 4, 2, 4, 2, 4 stepping for test divisors until sqrt(n) ie division … | |
Re: Worth to sort combined list first for iteration. For small ranges of integers there would be possibility for set solution (with little work this could produce ranges instead of individual integers). [CODE]lista = [(3015, 3701), (4011, 5890), (10,40), (150,300)] listb = [(3045, 3800), (1,2), (100,200), (4500,6000), (20,145)] sets_a = set(value … | |
Re: Decorator constructs the function, which takes the original function as argument that happens when function definations are created, after the meaning of original function becomes changed to include the additions from decorator. | |
Re: possibly there is ftp access: [url]http://docs.python.org/library/ftplib.html[/url] | |
| |
Re: It is same: density translates directly to volume/weight. | |
Re: Representatiom for atoms, conses, lambda expressions and special forms like setq. | |
Re: Your description is scrambled, do you want to remove duplicates from list? Like: [CODE] [['Value1', 'Value2', 'Value3'], ['Value1', 'Value2', 'Value3'], ['Value1', 'Value2', 'Value3'], ['Value1', 'Value2', 'Value3']] becomes [['Value1', 'Value2', 'Value3']][/CODE] |
The End.