3,386 Posted Topics

Member Avatar for NekoChan
Member Avatar for NekoChan
0
818
Member Avatar for TrustyTony

Do you know that there is clean way of doing what C-language ternary operator ? does in Python's recent versions. It is if with special twist. The syntax is: [CODE]'The value if true' if <condition> else 'Value when false'[/CODE] Values can be any type. You can put this structure to …

0
1K
Member Avatar for Robertbra

How about this if your code is right (need only simple length, not need to count each word only once, sort or something) ((code) button is useful for posting readable programs): s="""An Oligonucleotide is a short segment of RNA or DNA, typically with twenty or fewer bases. Although they can …

Member Avatar for TrustyTony
0
112
Member Avatar for pratz

You could check places like [url]http://python.computersci.org/Fundamentals/TheBasics[/url] or [url]http://www.razorvine.net/python/PythonForJavaProgrammers[/url] Which try to explain Python for people with Java background For using of classes, it is best to try to read some example programs, like [url]http://www.daniweb.com/code/snippet216596.html[/url]

Member Avatar for snippsat
0
249
Member Avatar for dbphydb

You must give the page html at least to check it out by somebody with experience in web pages (more than me).

Member Avatar for Tech B
0
2K
Member Avatar for alakaboom1

I just can not understand structure of organizing modules. Usually level two would be created on completion of level 1, either in chain fashion or by returning control to the main loop.

Member Avatar for TrustyTony
0
136
Member Avatar for Tech B

Could we get one 'im' as sample to do true test of the function? Use attachment and zip the file if it is not accepted as it is (GIF?)

Member Avatar for TrustyTony
0
233
Member Avatar for lsmurfl

I like this suggestion of random number n between 0..364 and comparing to set of earlier generated birth day numbers, and then converting to Month/day acccording to list of days until end of month of each month of year (or using built in function to calculate date n days after …

Member Avatar for griswolf
0
256
Member Avatar for toadzky

[CODE]for bunchofhex in [r'\x45\x23\x67',r'\x123456']: print bunchofhex bunchofhex = bunchofhex.split(r'\x') print bunchofhex value = int('0x'+''.join(bunchofhex),0) print '%i = 0x%x' %(value,value) print '-'*40 [/CODE]

Member Avatar for TrustyTony
0
185
Member Avatar for cyon

Quite same as Gribouillis but here anyway (find_dup as generator, here put to list by list()): [CODE]L = [ 'oranges' , 'apples' , 'oranges' , 'grapes', 'oranges' ] def has_dup(li): return len(li) != len(set(li)) def find_dup(li): s= set() shown = set() for item in li: if item in s - …

Member Avatar for TrustyTony
0
2K
Member Avatar for vello

I think nobody tries to be nasty. However I little generalized and gave up using find in my old multisearch. I think this parsing could be useful start. [CODE]inp=['2x+x','2x-1y+3x+2'] def multis(s,text,start=0): x='' for ch in text[start:]: if ch in s: if x: yield (x,ch) else: yield ch x='' else: x+=ch …

Member Avatar for vello
-3
141
Member Avatar for qqabb

I would little clean up -ordi- code: [CODE]def binary_search(a, required): start = 0 end = len(a) - 1 answer = None while start <= end: middle = (end + start) / 2 if a[middle] == required: answer = middle break elif required < a[middle]: end = middle - 1 else: …

Member Avatar for TrustyTony
0
1K
Member Avatar for shwick

My opinion is that it can be done [B]without[/B] re. [CODE]# tested with python 2.6 and 3.1 sentences = """ You would stomp <mob> into the ground. <mob> would be easy, but is it even worth the work out? No Problem! <mob> is weak compared to you. <mob> looks a …

Member Avatar for TrustyTony
0
110
Member Avatar for cyon

After few proofs I found this way: [CODE]>>> s = '34, 58' >>> print ( tuple( int(i) for i in s.split(', ') ) ) (34, 58) >>> [/CODE]

Member Avatar for ultimatebuster
0
7K
Member Avatar for blazahjazz

Here is generator solution: [CODE]def xox(n): if n==0: yield '' elif n==1: yield 'X' yield 'O' else: for start in xox(n-1): if not start.endswith('O'): yield start+'O' yield start+'X' print 'xox(5) = ',list(xox(5)) [/CODE] [CODE] ['XOXOX', 'XOXXO', 'XOXXX', 'XXOXO', 'XXOXX', 'XXXOX', 'XXXXO', 'XXXXX', 'OXOXO', 'OXOXX', 'OXXOX', 'OXXXO', 'OXXXX'] [/CODE]

Member Avatar for griswolf
0
157
Member Avatar for ktsangop
Member Avatar for valorien

[CODE]>>> hex(234235) '0x392fb' >>> int('0x392fb',16) 234235 >>> 234235 << 4 3747760 >>> hex(_) '0x392fb0' >>> a=0x00E2 >>> b=0x0F80 >>> print hex(a & b) 0x80 >>> [/CODE]

Member Avatar for Gribouillis
0
14K
Member Avatar for hadoque

Something like this: [CODE]# -*- coding: cp1252 -*- from Tkinter import * from ScrolledText import * def filein(): ## mainObject.file2List(textFile.get()) mywin = ScrolledText() mywin.pack(fill=BOTH, expand=YES) mywin.insert(END,open(textFile.get()).read()) win = Tk() win.title("Upprepade ord") textFileButton = Button(win, text = "Läs in") textFileButton.grid(row = 2, column = 2) textFile = StringVar() textFileEntry = Entry(win, …

Member Avatar for hadoque
0
472
Member Avatar for pietromarchy
Member Avatar for pietromarchy
0
674
Member Avatar for vello

If you learn simple list comprehensions you can do simpler way (python 2.6) [CODE]for limit in (-1,1,3): print [y in x if y>limit][/CODE]

Member Avatar for TrustyTony
-1
161
Member Avatar for nramya82

Task has no connection to line count only total number of characters collected except # lines. Here if all characters are included in the count including (excluding exception handling, without using with) does not work if file is shorter than 1000 chars (one line fix, exercise for the student): [CODE]def …

Member Avatar for TrustyTony
0
113
Member Avatar for pythonnewbie10

Hint: [CODE]line='Fred, Nurke, 16, 17, 22' line=line.split(',') numbers=[float(mark) for mark in line[2:]] average = sum(numbers)/len(numbers) print "%s, %s: %.1f" % (line[0],line[1], average) [/CODE]

Member Avatar for TrustyTony
0
113
Member Avatar for bjoernh
Member Avatar for atsuko

Maybe could adapt my earlier multimatcher to be more restrictive: [CODE]# multiple searches of a string for a substring # using s.find(sub[ ,start[, end]]) import string def multis(search,text,start=0): while start>-1: f=text.find(search,start) start=f if start>-1: if ((text[start-1] not in string.letters) and (text[start+len(search)] not in string.letters)): yield f start+=1 paragraph = '''This …

Member Avatar for TrustyTony
0
706
Member Avatar for linuxoidoz

Unicode string has potentially very many letters that does not fit to ASCII range. utf8 however can encode them in variable length codes (Python 2.6, python 3 has many changes for the system) [CODE]a=u'asfasdfö' b=a.encode('utf8') print a print b [/CODE] However wikipedis says: [QUOTE]The Python language environment officially only uses …

Member Avatar for Gribouillis
0
202
Member Avatar for py.thon

You forgot your code and or pseudo code. Also it is good to use the code tags (# button in toolbar) to put output text in post as it gets messed up, even it is not really code. If you put any one formatting in it for any part of …

Member Avatar for ANTALIFE
0
825
Member Avatar for rahul8590

Please not use tabs. [CODE]import sys, os def cat(filename): f = open(filename) text = f.read() print '----', filename print text args = sys.argv[1:] for arg in args: cat(arg) [/CODE]

Member Avatar for rahul8590
0
197
Member Avatar for oaktrees

Print is debuggers best friend [CODE] import string values=['']*6 values[5]="12234.7B" holder=[] print string.letters print values print values[5].letters holder.append(values[5].letters) [/CODE]

Member Avatar for oaktrees
0
118
Member Avatar for WildBamaBoy

totalTime is variable and it can not be called as function as it has not function value.

Member Avatar for WildBamaBoy
0
2K
Member Avatar for spikeru

if you want to really copy iterable, you should use slice: [CODE] returnDataArray = dataArray ==> returnDataArray = dataArray[:][/CODE]

Member Avatar for TrustyTony
0
503
Member Avatar for ihatehippies

Do you need to take from every list? 6 is only number in two lists. Why can not take 4 from third list?

Member Avatar for TrustyTony
0
167
Member Avatar for pythonnewbie10

Go from small to big in implementation, from the whole to parts in writing the pseudo code of things to do. Read the pseudo code and play stupid (i.e. computer), can you arrive in solution or did you miss something? Implement function, do test in main routine to test it …

Member Avatar for TrustyTony
0
172
Member Avatar for Greyhelm

berol is both object instance and parameter to method, which already has self parameter. I would organize location for a object as its property and moving to other location with only one parameter, the destination. Object instances would be occupant values of one place instance. Object would move by giving …

Member Avatar for Greyhelm
0
10K
Member Avatar for jeffjpeterson
Member Avatar for jeffjpeterson
0
284
Member Avatar for macca21

ord is built in function to find numeric value of character, please rename the object instance. Why there is this order instance in class level common to all orders? Looks like you are replacing old orders every time new order is made, but then how do you know about earlier …

Member Avatar for snippsat
0
297
Member Avatar for oaktrees

Hint: [CODE]data='$ 235.0 M' print data.lstrip('$ ') print data.rstrip(' M') [/CODE]

Member Avatar for oaktrees
0
136
Member Avatar for vlady

You need to put global known in your function. put [ICODE]t0=time.clock()[/ICODE] before and after [ICODE]print time.clock()-t0[/ICODE] to see how long it took. But put the timing in main function as you need total not time for each call of fibonacci. Nice example of lookup function.

Member Avatar for vlady
0
148
Member Avatar for swerty4

put lower() after read().: [ICODE]words = set(open('mispel.txt').read().lower().split())[/ICODE] Do you need to suggest correct spelling for the incorrect words?

Member Avatar for swerty4
0
136
Member Avatar for gorbulas

I could not quite fathom your code but I did the following: [CODE] # For storing information about auctions class AuctionList: def __init__(self,data=[]): self.auctionData=data # Add an auction to the list def Add_Auction(self,info): print 'Before',self.auctionData self.auctionData.append(info) print 'After',self.auctionData def __len__(self): return len(self.auctionData) def __str__(self): return str(self.auctionData) auction2=AuctionList(['line 1']) auction_list=AuctionList(['line 1']) …

Member Avatar for gorbulas
0
375
Member Avatar for lightning18

I would prefer to formulate the SoulMazer's code like this [CODE]#!/usr/bin/python text1 = "user" # Change to whatever you would like f = open("D:/Python26/LICENSE.txt", "r") for lineno,line in enumerate(f.readlines()): if text1 in line.lower(): print "Word found at line", lineno+1 [/CODE]

Member Avatar for lightning18
0
139
Member Avatar for juanjo-argentin

I do not know if this filter is enough exclusive as I do not check the length of numbers but: [CODE]test= '100|1999|pepito|False|27-10655374-1|False|||05/09/1952|1|4||3||1|1|8|67||4|False|True|False|oerirabtaa||||Femenino|0|0|0|0|0|0|2|' testlist = test.split('|') for t in testlist: if t.translate(None,'0123456789')=='--': ## take out all numbers and compare print t """ Output: 27-10655374-1 """ [/CODE]

Member Avatar for juanjo-argentin
0
88
Member Avatar for jmark13

Like this: [CODE]>>> a='010101010101010101010101010101010101010101010101010101010101' >>> a=int(a,2) >>> a 384307168202282325L >>> [/CODE]

Member Avatar for jmark13
0
876
Member Avatar for xleon

[QUOTE=Tech B;1228060]testzip is to check the integrity of the files within the zip. To check if a zip itself is corrupt, pass it through a try statment. [code] import os, zipfile mylist = os.listdir("C:\myzipfiles") [/code] [/QUOTE] Little less stupid listing [code] import os, zipfile mylist = [zip for zip in …

Member Avatar for xleon
0
4K
Member Avatar for DancingDana

Alternatively chdir to directory before import. Your must user __import__() function not the statement. However it is little strange that you would need to do what you are asking. Could you maybe introduce the function of your program in rough pseudo code so maybe we could find you better alternative …

Member Avatar for TrustyTony
0
143
Member Avatar for jodhy

This is Python forum. Show effort to write the code and in case of problems post to Pascal/Delphi group your code and description of your problem. Luck with coding!

Member Avatar for TrustyTony
-1
89
Member Avatar for cableguy31

This way you can find those names, just replace your action in place of print. [CODE]inp="""Share name Type Used as Comment -------------------------------------------------------------- Data Disk Data2 Disk My Docs Disk Users Disk The command completed successfully.""" for line in inp.splitlines(): if line[14:18]=='Disk': print line[0:13].rstrip() """Output: Data Data2 My Docs Users """ …

Member Avatar for TrustyTony
0
403
Member Avatar for docesam

There is this one small unknown web service called YouTube for example: [url]http://digg.com/programming/YouTube_is_almost_entirely_written_in_Python[/url]

Member Avatar for TrustyTony
-4
329
Member Avatar for prashanth s j
Member Avatar for niehaoma

Your code is quite well, anyway two more ways to do it: masking with 0b1111 and using the bin representation string: [CODE]## 1) do it yourself with masking def nibble(n,x): ## mask 0b1111 shift up, mask, shift back return ( x & ( 0b1111 << (4 * n) ) ) …

Member Avatar for niehaoma
0
273
Member Avatar for jib

The End.