3,386 Posted Topics

Member Avatar for johnwoods87
Member Avatar for catintp
0
126
Member Avatar for pythonbegin
Member Avatar for Memphis_212

So you want example of accumulate pattern different from yours? You should accumulate string result and put space between words, because you want to return string. Normaly in Python we would use ' '.join(generate_the_words) but that is other, generator pattern. Looks like you could use little repetion of how functions …

Member Avatar for TrustyTony
0
1K
Member Avatar for WolfShield

You would have your main program separated from utilities and have the root window defined there: [CODE]import tkinter as tk import button # no .py import entry root = tk.Tk() root.title("Import Test") e = entry.a(root) # need to define function b = button.b(root) # need to define function button.print_it() root.mainloop()[/CODE]

Member Avatar for TrustyTony
0
1K
Member Avatar for LoveMyPadres

Here for future version functioning version of Woooee's fast code using after-timing: [CODE]import time from Tkinter import * def change_color(canvas, ov, color): color = 'yellow' if (color != 'yellow') else 'blue' print "color =", color canvas.itemconfig(ov, fill=color) canvas.update_idletasks() canvas.after(1500, change_color, canvas, ov, color) root = Tk() root.title('Canvas') canvas = Canvas(root, …

Member Avatar for LoveMyPadres
0
2K
Member Avatar for henryford

Value of name, Names, Workhours, Wages. EmpDOne and result of last line is not used. Capitalized name is supposed to mean object value by convention.

Member Avatar for TrustyTony
0
137
Member Avatar for Klustor

Do global search and replace for listcomputers to self.listcomputers to save the value in the object. You could use lot of refactoring, I would for example store the [CODE]wx.Font(8, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 0, 'Microsoft Sans Serif')[/CODE] to one variabel to make it easier to change in future and to make …

Member Avatar for Klustor
0
538
Member Avatar for James0l9l
Member Avatar for TrustyTony
0
165
Member Avatar for Malinka
Member Avatar for scobie

Line 44 sets variable to 1 and it will be incremented, that will only be made zero if it is allready zero (test in line 54, assignment line 57. Would this be what you are after little cleaner and closer to your comment? [CODE]import Tkinter from tkFileDialog import askopenfilename root …

Member Avatar for TrustyTony
0
338
Member Avatar for crsher

I think some student you know has studied Python programming, which is ideal for this. He surely want to show us his efforts of programming this :)

Member Avatar for TrustyTony
0
2K
Member Avatar for Michael_Levin

Best algorithm for this is normally: [code]Select set of test cases While test cases do not pass Do next part of solution Solve test cases Debug While too slow See if you can use c-coded functions to produce same solutions for test cases. Profile [/code]

Member Avatar for TrustyTony
0
187
Member Avatar for HoneyBadger

addhex(hexdigit) = hextable[hexdigit], with hextable global variable. Change the name as it has nothing to do with addition. Input must be key in the table.

Member Avatar for HoneyBadger
0
457
Member Avatar for TrustyTony

This handy function turns file into stream of words stripped of punctuation, whitespace and digits, but does not split for example we'd to two words. If you want that you can further process yielded words or change the definition.

Member Avatar for griswolf
3
2K
Member Avatar for Asset

[CODE] total = float(numList[i]) total = total + numList[i] [/CODE] What are you trying to do, obviously [COLOR="Red"]numList [/COLOR]is a [B]strList[/B]. You are trying to double the value of numList[i]? why not [CODE]total = 2 * float(numList[i])[/CODE]

Member Avatar for Asset
0
713
Member Avatar for Teiji

You would run the test from [B]command window [/B]or you would [B]double click[/B] the file in graphical file manager.

Member Avatar for TrustyTony
0
366
Member Avatar for TrustyTony

I write usually many versions of the functions, sometimes writing functions from scratch again. Sometimes the parameters change from version to version, sometimes they are refering to library of functions that also has multiple versions. Has somebody advice on how to manage best this kind of situation? Should I define …

0
135
Member Avatar for j855

Push numbers (or heapify inplace) in heap and use heapq.nlargest heapq.nsmallest

Member Avatar for TrustyTony
0
113
Member Avatar for masumar

For Python 3 solution this is simplest: from collections import Counter print(Counter(line.rstrip() for line in open('data.txt')))

Member Avatar for TrustyTony
0
429
Member Avatar for br0wnm4n

For code clean up I would take also this block of code: [CODE] lst = [] for n in d: lst.append(n) lst.sort() [/CODE] Question to OP: how many times lst is sorted? I would think that instead of [CODE] for word in words: if word not in d: d[word] = …

Member Avatar for TrustyTony
0
120
Member Avatar for bambi231991
Member Avatar for TrustyTony
0
127
Member Avatar for sijei

You should post runnable code of what you have. First the first program and remember to push **Code** before pasting.

Member Avatar for TrustyTony
0
127
Member Avatar for henryford
Member Avatar for bpross22

What is your problem? What is purpose of overriding the file type? Why are you using count when you append to list all lines splitted? How is RoomTable initialized? You are passing file name, call the string file. You are using it as filename string and override built in type …

Member Avatar for woooee
0
214
Member Avatar for pacers10

Can you give description of your algorithm for red_pixel function? You should change the capital letter words to underscore words if you are allowed (PEP 8 conventions). What is your problem and tell how have you tried to debug it. Give also exact error messages.

Member Avatar for woooee
0
142
Member Avatar for shashi86

Please try not to give ready answers to homework questions and push Code button before pasting your code to message.

Member Avatar for TrustyTony
0
190
Member Avatar for knan

There is an interesting alternative which you easily miss as possibility: [CODE]dictionary={'a':['A'], 'b':['B'], 'c':['C']} for k,v in dictionary.items(): [dictionary[k]] = v print dictionary [/CODE] And here is version I would use in my code: [CODE]dictionary={'a':['A'], 'b':['B'], 'c':['C']} dictionary = dict((k, v) for k,[v] in dictionary.items()) print dictionary [/CODE] And finally …

Member Avatar for TrustyTony
0
150
Member Avatar for knan

t-one or t-el? Maybe there would exist clearer variable names? By the way have you learned about list comprehensions?

Member Avatar for Gribouillis
0
158
Member Avatar for br0wnm4n

[CODE]def index(filename, words): infile = open(filename) content = infile.readlines() infile.close() count = {} for word in words: if word in count: count[word] += 1 else: count[word] = 1 for word in count: print('{:12}{},'.format(word, count[word])) [/CODE]

Member Avatar for br0wnm4n
0
250
Member Avatar for henryford

Beauty is in the eye of beholder, I have written super simple pretty printer as I did not like the result of pprint module for shallow lists. I could think that object with pretty format template attribute settable from user would not be bad thing, just remember to keep repr …

Member Avatar for richieking
0
152
Member Avatar for -ordi-

You are comparing the generator n to integer instead of reading values from it, I do not understand. Mitä häh?

Member Avatar for woooee
0
137
Member Avatar for newbieha
Member Avatar for TrustyTony
0
92
Member Avatar for knan

Find the mathematical base for what you want to do and find what is this function named mystery here in standard library (the import of module left out here): from ____ import ____ as mystery x=[['a', 'b', 'c', 'd'], ['e', 'f'], ['g', 'h']] for sub in x: print list(mystery(sub,2)) print …

Member Avatar for Gribouillis
0
152
Member Avatar for sravi.pearl

Cleaner map solution as lambda is not needed: [code]a = map(int, a)[/code]

Member Avatar for TrustyTony
0
95
Member Avatar for novice20
Member Avatar for Gribouillis
0
131
Member Avatar for UaBoy

There is many ways to reprecent group of information. Basic choice is list for changing data or tuple for rarely changing data. Tuple is faster but any change to it generates new tuple as it is immutable. Please go through the tutorials section on types.

Member Avatar for TrustyTony
0
120
Member Avatar for ChaosKnight11

I understand that as C for example is compiled the Python program is allowed to be 10 times slower. Maybe not so bad as you can prepare normally running program in 1/8 of the time and rest of time you can optimize.

Member Avatar for woooee
0
186
Member Avatar for knan

[QUOTE=griswolf;1368361]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 …

Member Avatar for TrustyTony
0
203
Member Avatar for kafro
Member Avatar for Bombshock

subtle issue: it is better not to build the list if it is not saved for future, join is happy with generator: [CODE]import re # use regex package pingPatternRe = re.compile('=([0-9.]+) ms') # compile the pattern I want to recognize with open('randomcharacters.txt') as f: # open the file so as …

Member Avatar for TrustyTony
0
218
Member Avatar for pacers10
Member Avatar for TrustyTony
0
165
Member Avatar for DocBreen

Or you can do: [CODE]print hangword.count(guess) [/CODE] or [CODE]>>> hangword ='Tony Veijalainen' >>> hangword = hangword.lower() >>> guesses ='a' >>> print ' '.join((letter if letter in guesses else '_') for letter in hangword) _ _ _ _ _ _ _ _ _ a _ a _ _ _ _ >>> …

Member Avatar for TrustyTony
0
113
Member Avatar for Iron-Man1138
Member Avatar for yari

Here is my solution of finding right place guesses and wrong place guesses, result contains '*' for correct place letters and '-' for wrong place letters, other letters are from secret word: [CODE]def check(guess,word): result=['*' if c1==c2 else c2 for c1,c2 in zip(guess, word)] for index, char in enumerate(guess): if …

Member Avatar for TrustyTony
0
2K
Member Avatar for Teiji

I suggest reading this, I have it still it in my plan for reading as I have not yet dealt with the topic. [url]http://diveintopython.org/unit_testing/index.html[/url]

Member Avatar for TrustyTony
0
146
Member Avatar for iwanttolearnc

jpeg quality setting is same in the files as checked in image editor like IrfranView? But, wait a moment the size looks right for me: 3 primary colors * 300 * 300 == 270 000

Member Avatar for iwanttolearnc
0
84
Member Avatar for AutoPython

Additionally what happens when user inputs key 123456? Why you use global variables, not parameters. Also would be natural to return values.

Member Avatar for AutoPython
0
200
Member Avatar for JJHT7439

For me looks like line 4 should be [B]while[/B] not if, from the comment, so it can remove more than one trailing zero.

Member Avatar for Gribouillis
0
3K
Member Avatar for pythonlearning
Member Avatar for qingmui

[CODE]#===============E 3======================== # This allow any number you want def dvsble(x,y): for n in range(x,y): sum = 0 if n%17 ==0: x = n sum() print n else: n=n+1 print sum[/CODE] Some comments to help going forward: [LIST=1] [*]Are the parameter choice correct considering restrictions of this request [*]Line 5 …

Member Avatar for TrustyTony
0
270

The End.