3,386 Posted Topics

Member Avatar for TrustyTony

I had posted here already here to forum a [beautiful code for solving Sudoku puzzles](http://www.daniweb.com/software-development/python/code/294304/eleagant-and-fast-sudoku-with-generator-expressions), so I was in kind of dilemma what to do, as I read the task to do a sudoku solve as one task in Project Euler. To use the code from before and just take …

Member Avatar for TrustyTony
0
894
Member Avatar for TrustyTony

Saw somebody was viewing this thread and thought the qrange needed one update. From post [url]http://www.daniweb.com/code/snippet216627.html[/url].

Member Avatar for TrustyTony
0
635
Member Avatar for Alex.

[CODE]print('\n'.join('%s, %s' % t for t in [(182, 'the'), (128, 'and'), (123, 'will')]))[/CODE] Newer and quite useful format: [CODE]print('\n'.join('{1}, {0}'.format(*t) for t in [(182, 'the'), (128, 'and'), (123, 'will')]))[/CODE]

Member Avatar for richieking
0
102
Member Avatar for tcl76

This is marked solved, but here is my style of solution also: [CODE]s= '00101' res = tuple('Lane fail {place}.'.format(place =index) for index, value in enumerate(reversed(s)) if value == '0') print '\n'.join(res) if res else 'All lanes pass' """ Output: Lane fail 1. Lane fail 3. Lane fail 4. """ [/CODE]

Member Avatar for TrustyTony
0
139
Member Avatar for TrustyTony

Here is my newest version of the pretty printer I posted earlier. Not doing all that fancy stuff of printing looped recursive structures, but if you put one deeper structure inside flat one, works better for me than pprint module. I do not use often object oriented structures though. Dedicated …

0
662
Member Avatar for rssk

Length is simple number and can not be iterated. You need one function starting with r or x to produce sequence of values.

Member Avatar for rssk
0
176
Member Avatar for akshayreddy
Member Avatar for raschko

To my mind comes at least using numpy for generating the point list. Numpy was missing from your list.

Member Avatar for raschko
0
164
Member Avatar for Dane2259

[QUOTE=Dane2259;1463249]Could someone explain to me why this code will not print the 10th prime number? It says there is a syntax error on the fourth line (the x = range(3, math.sqrt(test_num)). It also says there is a syntax error on the sixth line (while prime_count < 10:). import math test_num …

Member Avatar for richieking
0
123
Member Avatar for CharlieNewey

It is considered bad, because this time for example you had same bug repeated 14 times in your code, for example. Instead insert print functions and any input statement for pause or use debugger break points and watches.

Member Avatar for CharlieNewey
0
688
Member Avatar for ampoliros
Member Avatar for ampoliros
0
2K
Member Avatar for Geemon

[QUOTE=;][/QUOTE] how about doubling key 'north' as 'n' etc and get rid of the if. Would only use try except to catch incorrect input.

Member Avatar for griswolf
0
209
Member Avatar for Cesiumlifeboat

prove putting copy slice everywhere where there is append i.e. [code]Npray.append(pray[:])[/code] please take out capitalzed names and use python_style_names ;) Are you sure about repeating lines 45 vs 47? I would also check namedtuple type for making nice named access to attributes.

Member Avatar for woooee
0
128
Member Avatar for triksterx

You must pack or grid from the stored variable. Otherwise you get value None. Similarly as append and sort methods return None. That means they are procedural not functinal.

Member Avatar for TrustyTony
0
2K
Member Avatar for ramesh125
Member Avatar for quinnifir

I do not like much your style and I am not OO guru, but this at least shows the info if you happen to guess correct name exactly (I did it to use only lowercase to make it little easier): [CODE] ---- snip, snip --------- def open(self, first, last): file_name …

Member Avatar for TrustyTony
0
123
Member Avatar for Archenemie

Looks like you use class when you should have module. Your numbers class have not any numeric value. The same function exist in module operator as operator.add and operator.mul. Nothing stops you to use sum function instead of operator.add. I would not use input in Python 2.

Member Avatar for Archenemie
0
180
Member Avatar for jintujacob
Member Avatar for TrustyTony
0
104
Member Avatar for jordan0420

Just link to the file name, not save file object. You must probably use full path names à la os.path.abspath.

Member Avatar for jordan0420
0
914
Member Avatar for LadyRelm2

Do help(humansize) or dir(humansize) and call the main function of the file. Why can you not open the file normally and run it from editor side by F5. Final testing is better done without IDE from CMD prompt or launch the program by double clicking the file. I currently like …

Member Avatar for snippsat
0
1K
Member Avatar for TrustyTony

I have left my source of information as docstring comment on code side. If you want to solve the problem yourself do not run the code. This code actually gives the correct answer. I have not reacted to the border case comment in my formula source as it is quite …

0
1K
Member Avatar for Boubakr

You are looking wrong place. Check itertools.permutations and random.choise

Member Avatar for TrustyTony
0
154
Member Avatar for joywheels

I do not understand what you are doing this seen set stuff. By testing the code I understood you wanted to record the number of each word as it occurs. I would do for example like this instead of the length stuff: [CODE]from __future__ import print_function try: input = raw_input …

Member Avatar for TrustyTony
0
131
Member Avatar for blenkhn
Member Avatar for blenkhn
0
896
Member Avatar for zizuno

You don't need destroy anything, what user sees need not be same as program sees. See the forget method, the opposite of pack.

Member Avatar for TrustyTony
0
672
Member Avatar for jamd200

I would do two variable assignment instead of temp variables needed in other languages. Looks nice code inspite of this point. Irritates me though that there seems not be faster way to split list for quicksort than doing two passes of list with complement conditions.

Member Avatar for jamd200
0
346
Member Avatar for jamd200

This could prove helpfull seeing the amount of your code: [URL="http://en.wikipedia.org/wiki/Code_refactoring"]Code refactoring[/URL]

Member Avatar for jamd200
0
231
Member Avatar for jordan0420
Member Avatar for ShadyTyrant

Alternative approach can be found in my code snippet [URL="http://www.daniweb.com/code/snippet285434.html"]Super simple one word anagrams[/URL] and follow up with immediate response by preparing lookup in file of all anagrams for future use: [URL="http://www.daniweb.com/code/snippet288327.html"]One word anagrams by lookup[/URL]

Member Avatar for ShadyTyrant
0
586
Member Avatar for dynaflex

So the code should be like my lookup version only missing the saving of anagram file.

Member Avatar for TrustyTony
0
99
Member Avatar for dynaflex
Member Avatar for -ordi-

Here in this [URL="http://www.daniweb.com/forums/post1245223.html#post1245223"]old thread [/URL]is my code for example for the dynamic programming algorithm for lcs (longest common substring). The link points to version were I only keep one row of record, but original algorithm was indexing normal array.

Member Avatar for richieking
0
175
Member Avatar for Ashena

If you have saved the data from your program, I would change thd file output to use cPicle or JSON formats. That leads to cleaner, more maintainable code.

Member Avatar for Ashena
0
413
Member Avatar for vbx_wx

[CODE]class A: def __init__(self): print 'A()' class B(A): def __init__(self): A.__init__(self) print 'B()' class C(B): def __init__(self): B.__init__(self) print 'C()' c = C() [/CODE]

Member Avatar for vbx_wx
0
131
Member Avatar for Ene Uran

Close the pylab window and the prompt comes back and your print will print.

Member Avatar for Flintstone_
2
2K
Member Avatar for novice20

Looks like it has both repr and string form, so you should have not any difficulty finding data using those: [url]http://pysnmp.sourceforge.net/docs/2.x/asn1-octetstring-objects.html[/url]

Member Avatar for LoveMyPadres
0
2K
Member Avatar for Boubakr
Member Avatar for felix001

Looks little over complicated for me. We do not need datetime objects. [CODE]import string def only_numbers(x): res= int(x.replace('-','').strip(string.letters + string.punctuation)) # print res return res files = ('site-website-20110105-101303.jpa', 'site-website-20110108-094822.jpa', 'site-website-20110108-095834.jpa', 'site-website-20110109-203148.jpa', 'site-website-20110110-040326.jpa', 'site-website-20110106-163312.jpa', 'site-www.website-20110109-040402.jpa', 'site-www.website-20110111-040219.jpa') print('Files sorted:\n\t' + '\n\t'.join(sorted(files, key = only_numbers)))[/CODE]

Member Avatar for felix001
0
162
Member Avatar for Smed

Python has very flexible max function, which you can use with enumerate like above: [CODE] # put definition in function for reuse, put the definitions mainly in beginning of the file def max_with_ignore(seq, not_these): """ this function takes sequence and set (or less efficiently list) of exception indexes and returns …

Member Avatar for TrustyTony
0
126
Member Avatar for meensatwork
Member Avatar for nima3188

Here you are richiekid ;) Concised version of the whole code. [CODE]with open('test.txt', 'w') as locx: locx.write('\n'.join(str(i) for i in range(9))) [/CODE]

Member Avatar for nima3188
0
130
Member Avatar for hema dhevi.N

[code]#untested values = [] for count in range(int(raw_input('Number of inputs'))): values.append(raw_input('%i:' % (count+1))) [/code]

Member Avatar for TrustyTony
0
2K
Member Avatar for kailashbuki

Yes, richieking, I see that this n-gram are starting from every letter of the document, so my suggestion would be instead of wooees dict to record something like file position counter for n-gram starting positions. Would add quite a lot to space requirements though. To speed things up you would …

Member Avatar for TrustyTony
0
191
Member Avatar for fredfredfred

Could you give sample of your coding, say one function with proper docstring documentation, so maybe we can give you advice on your style.

Member Avatar for TrustyTony
0
141
Member Avatar for skaliam
Member Avatar for Hodir
Member Avatar for -ordi-
Member Avatar for TrustyTony
0
182
Member Avatar for Blackberryy

Red rectangles looks same size for me and spacing is also constant. Role of spacing rectangles and red rectangles only alternate with spacing white ones. 3 white, 3 red, 3 white .... Swap the spacing and rectangles after each line: [CODE]rect, spacing = spacing, rect[/CODE]

Member Avatar for richieking
0
2K
Member Avatar for vbx_wx

I think easiest would be to just post process apropriately the last match from list of matches. You could also prove \w+ instead of \D+.

Member Avatar for TrustyTony
0
87
Member Avatar for JJHT7439

Little logic, even partial, included works also miracles for speed, even when generating all permutations: [CODE] letters = ('s', 'm', 'e','n','d','o','r','y') coefs = (1000, 1000-10000, 100+1-10, 10-100, 1, 100-1000, 10, -1) def sendmoremoney(): # python 2 or 3 # solve SEND + MORE = MONEY by brute force with little …

Member Avatar for TrustyTony
0
334

The End.