3,386 Posted Topics

Member Avatar for sneekula

..when you start to write an algorithm for it if people are asking where you are going for holidays mumbling: hhmhh.. NP-hard....

Member Avatar for Netcode
0
674
Member Avatar for Niles64

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.

Member Avatar for Niles64
1
117
Member Avatar for TrustyTony

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 …

0
269
Member Avatar for thompsonSensibl

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?

Member Avatar for Momerath
0
86
Member Avatar for justin96b
Member Avatar for TrustyTony
0
273
Member Avatar for Lebowski

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 += …

Member Avatar for TrustyTony
0
411
Member Avatar for rahulroshan

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')

Member Avatar for TrustyTony
0
98
Member Avatar for user45949219

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): …

Member Avatar for Gribouillis
0
158
Member Avatar for Kleiner

[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]

Member Avatar for Kleiner
0
284
Member Avatar for D33wakar

%f and float n does not look integer to me, like your prompt and algorithm suggests.

Member Avatar for D33wakar
0
151
Member Avatar for farhanrocks
Member Avatar for Rashakil Fol
-3
287
Member Avatar for theCompiler
Member Avatar for sergent
0
289
Member Avatar for JoshuaBurleson

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 …

Member Avatar for nabla2
0
582
Member Avatar for JoshuaBurleson

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 …

Member Avatar for TrustyTony
0
501
Member Avatar for JoshuaBurleson

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''

Member Avatar for JoshuaBurleson
0
319
Member Avatar for pixeldroid

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 …

Member Avatar for pixeldroid
0
207
Member Avatar for Needshelp444

I think you should pass the root window to Toplevel: [CODE]from Tkinter import * root = Tk() win2 = Toplevel(root) [/CODE]

Member Avatar for Needshelp444
0
2K
Member Avatar for isendre

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):], …

Member Avatar for isendre
0
74
Member Avatar for pYnewb

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]

Member Avatar for Purkinje
0
570
Member Avatar for tubby123

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.

Member Avatar for JeffGrigg
0
143
Member Avatar for JeffOwens

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 …

Member Avatar for TrustyTony
0
126
Member Avatar for wfray

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. …

Member Avatar for TrustyTony
0
875
Member Avatar for TrustyTony

What does this print statement produce and why? Learned it today, I still must be a newbie. [CODE]print('%0*d' % (3, 7))[/CODE]

Member Avatar for Purkinje
1
195
Member Avatar for patto78

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 …

Member Avatar for TrustyTony
0
189
Member Avatar for Alex9385

[CODE]>>> b = a[a[:,2]==1] >>> b array([[ 0. , 0.01, 1. ], [ 1. , 0.02, 1. ]]) >>> [/CODE]

Member Avatar for TrustyTony
0
173
Member Avatar for menonnik

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 …

Member Avatar for menonnik
0
240
Member Avatar for halien

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 …

Member Avatar for bvdet
0
274
Member Avatar for shasta90

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) # …

Member Avatar for ~s.o.s~
0
1K
Member Avatar for mexabet

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].

Member Avatar for JeffGrigg
0
297
Member Avatar for Gribouillis

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__?

Member Avatar for TrustyTony
2
723
Member Avatar for blivori

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 …

Member Avatar for blivori
0
224
Member Avatar for [V]

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]

Member Avatar for TrustyTony
0
177
Member Avatar for heavy.is.happy

I do not see problem for that: [CODE]>>> a='13.33' >>> a=float(a) >>> a 13.33 >>> print(a-13.33) 0.0 >>> [/CODE]

Member Avatar for Gribouillis
0
130
Member Avatar for nishajain

Looks like C++ for me. Not "related to the C language as per the ANSI C standard." at least.

Member Avatar for m4ster_r0shi
-1
146
Member Avatar for theCompiler

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]

Member Avatar for TrustyTony
0
86
Member Avatar for tubby123

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.

Member Avatar for TrustyTony
0
134
Member Avatar for TrustyTony

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 …

Member Avatar for TrustyTony
0
372
Member Avatar for noobprogrammer

For example with [URL="http://lxml.de/"]lxml module[/URL] or standard modules: [url]http://wiki.python.org/moin/PythonXml[/url] (ElementTree)

Member Avatar for Gribouillis
0
150
Member Avatar for DragonSlayerX

'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 …

Member Avatar for DragonSlayerX
0
104
Member Avatar for hqt

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.

Member Avatar for TrustyTony
0
493
Member Avatar for JoshuaBurleson

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]

Member Avatar for JoshuaBurleson
0
299
Member Avatar for lrh9

[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 …

Member Avatar for TrustyTony
0
141
Member Avatar for tubby123

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 …

Member Avatar for tubby123
0
87
Member Avatar for miac09

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 …

Member Avatar for TrustyTony
-1
228
Member Avatar for Purkinje

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.

Member Avatar for Purkinje
0
195
Member Avatar for flebber

possibly there is ftp access: [url]http://docs.python.org/library/ftplib.html[/url]

Member Avatar for snippsat
0
2K
Member Avatar for menonnik
Member Avatar for thompsonSensibl
Member Avatar for Lerilaine

Representatiom for atoms, conses, lambda expressions and special forms like setq.

Member Avatar for TrustyTony
0
386
Member Avatar for fingerpainting

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]

Member Avatar for TrustyTony
0
653

The End.