Search Results

Showing results 1 to 40 of 45
Search took 0.01 seconds.
Search: Posts Made By: ghostdog74 ; Forum: Python and child forums
Forum: Python Sep 25th, 2007
Replies: 4
Views: 3,038
Posted By ghostdog74
it would be better to show a sample input file, your expected output as well.
to search in a file. just an example...considering i don't know what your file structure is like.

for line in...
Forum: Python Jun 14th, 2007
Replies: 5
Views: 2,695
Posted By ghostdog74
another way

>>> for i in range(len(sentence.split()),0,-1):
... print sentence.split()[i-1],
Forum: Python May 8th, 2007
Replies: 7
Views: 1,262
Posted By ghostdog74
Personally, i would use a loop for this.

num = 32
b1 = 10
b2 = 2
x = 1
while 1:
if num%(b2**x) < num:
x = x + 1
continue
Forum: Python Mar 29th, 2007
Replies: 7
Views: 7,258
Posted By ghostdog74
it's up to you. however its good to modularize so main() is definitely good to have.
Forum: Python Mar 29th, 2007
Replies: 7
Views: 7,258
Posted By ghostdog74
you can use splitext from os module

import os,shutil
def renamer(target) :
os.chdir(target)
for filename in os.listdir('.') :
print filename
newfilename =...
Forum: Python Feb 28th, 2007
Replies: 4
Views: 1,742
Posted By ghostdog74
For your particular example, you can convert your list to a string, then find 'a'

>>> a = [(' ', ' ', [('a', 'Scott'), ('9', 'vth')]), (' ', ' ', [('a', 'Jenny'), ('9', 'vth')])]
>>> b = str(a)...
Forum: Python Feb 21st, 2007
Replies: 3
Solved: Plural of Words
Views: 3,617
Posted By ghostdog74
there are some cookbook recipe in ASPN you can refer to.
here (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82102).
they may not be wat you want, but at least will give you a head start
Forum: Python Feb 21st, 2007
Replies: 2
Solved: Word in Text
Views: 1,196
Posted By ghostdog74
you should read the docs more. also googling with "Python word count" will show you some links to what you are looking for.
Forum: Python Feb 19th, 2007
Replies: 3
Views: 6,047
Posted By ghostdog74
you can read in line by line

for line in open("file"):
if "word" in line:
do_something(line)


you can read in one whole chunk

data = open("file").read()
Forum: Python Feb 19th, 2007
Replies: 5
Views: 15,767
Posted By ghostdog74
there are several ways.
1) reading with for loop

o = open("output","a") #open for append
for line in open("file"):
line = line.replace("someword","newword")
o.write(line + "\n") ...
Forum: Python Jan 27th, 2007
Replies: 5
Solved: Scalar product
Views: 2,985
Posted By ghostdog74
Or you could do this

import operator
a = (1,2,3,4)
b = (4,3,2,1)
print sum(map(operator.mul,a,b))
Forum: Python Jan 26th, 2007
Replies: 8
Views: 3,568
Posted By ghostdog74
Do you want to include decimals like 2.0 , 2.00000 etc as a whole number ??
Forum: Python Jan 26th, 2007
Replies: 9
Views: 4,147
Posted By ghostdog74
Most string manipulation problems can be solved with Python's string functions. Only very complex ones will need regexp. So try not to use regexp if possible. Of course if you are good at it , then...
Forum: Python Jan 26th, 2007
Replies: 8
Views: 3,568
Posted By ghostdog74
you need to put a decimal before doing the division:

>>> 6.0/4
1.5
>>> 6/4.0
1.5


or you can import future:
Forum: Python Jan 26th, 2007
Replies: 9
Views: 4,147
Posted By ghostdog74
hi, wow, getter harder.:-)
anyway, here's a rather crude way and i am sure there are better ways (using re). I did substitution first, then do the rest

>>> data_raw = """
... header
... [23 ]...
Forum: Python Jan 25th, 2007
Replies: 9
Views: 4,147
Posted By ghostdog74
sorry somehow i can't find my edit button, but anyway
a decimal/float looks like this : 245.332 or 4.5 or 74.32
so to match them, we need one or more digits, followed by "." and followed by one or...
Forum: Python Jan 25th, 2007
Replies: 9
Views: 4,147
Posted By ghostdog74
another way is to use the "|" special character.

>>> re.findall(r'\d+\.\d+|\d+',data_raw)
['20', '35', '40', '84', '100', '245.99']
>>>
Forum: Python Jan 25th, 2007
Replies: 15
Solved: Sorting
Views: 2,522
Posted By ghostdog74
i think its answered in the other thread
Forum: Python Jan 25th, 2007
Replies: 15
Solved: Sorting
Views: 2,522
Posted By ghostdog74
hi there
sure, re.findall(r"(\d+)",data_raw)
thanks
Forum: Python Jan 24th, 2007
Replies: 15
Solved: Sorting
Views: 2,522
Posted By ghostdog74
assuming data is as first posted:

>>> import re
>>> re.findall(r"\[(.*)\]",data_raw)
['20 ', ' 35 ', '40 ', '84 ', '100 ', ' 245', ' 260', ' 300 ', ' 440 ', ' 521 ', ' 650 ']


...
Forum: Python Jan 17th, 2007
Replies: 6
Views: 1,897
Posted By ghostdog74
can you try :


dates = [i for i in files for j in months if j in i ]
Forum: Python Jan 12th, 2007
Replies: 7
Views: 7,074
Posted By ghostdog74
another way...but you have to test it in different cases...

lst = [11, 'Dick', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Paul', 13456789]
slist = sorted(lst) #sort the list
min_num , max_str =...
Forum: Python Jan 11th, 2007
Replies: 6
Solved: Student GPA
Views: 2,091
Posted By ghostdog74
what is your error, and what is your expected output/results?
Forum: Python Jan 9th, 2007
Replies: 6
Views: 1,944
Posted By ghostdog74
if you don't want to change list1, you can do

list1dup = list1[:]
list3 = add_item(list1dup)
...
Forum: Python Jan 9th, 2007
Replies: 5
Views: 2,544
Posted By ghostdog74
if you just want to find "Paul" in your example, one way to do it is to convert that list to string

astring = ','.join( str(i) for i in nested_list)
if "Paul in astring:
print "Found"
Forum: Python Jan 7th, 2007
Replies: 2
Views: 1,004
Posted By ghostdog74
this is the problem

grade = input("Enter gradepoint for course (Enter to quit): ")


input() expects a number. when you just press enter, it gives error
maybe a try:except can solve the...
Forum: Python Dec 29th, 2006
Replies: 4
Views: 1,120
Posted By ghostdog74
if your lists comparing only numbers, you can sort them first?

if sorted(li) == sorted(li2):
do something
Forum: Python Dec 5th, 2006
Replies: 19
Views: 6,262
Posted By ghostdog74
def en_de_code(text,flag=0):
if flag == 0:
return ''.join([chr(ord(char) + 1) for char in text ]) #encode
else:
return ''.join([chr(ord(char) - 1)...
Forum: Python Dec 2nd, 2006
Replies: 8
Views: 5,815
Posted By ghostdog74
In Python docs first para here http://www.python.org/doc/2.4.1/lib/typesmapping.html

"""
2.3.8 Mapping Types -- classdict
A mapping object maps immutable values to arbitrary objects. Mappings...
Forum: Python Dec 1st, 2006
Replies: 2
Views: 13,113
Posted By ghostdog74
do you want to comment out "import sys" and try again?
Forum: Python Dec 1st, 2006
Replies: 4
Views: 2,465
Posted By ghostdog74
>>> a = []
>>> if a:
... print "not empty"
...
>>> b = ['a']
>>> if b:
... print "not empty"
...
not empty
>>>
Forum: Python Oct 23rd, 2006
Replies: 4
Solved: reading a list
Views: 2,186
Posted By ghostdog74
hmm.list comprehension?


alpha = [ c for c in list if str(c).isalpha()]
number = [ c for c in list if str(c).isdigit()]


if you want to get unique elements, use set
Forum: Python Oct 19th, 2006
Replies: 3
Solved: xrange() result
Views: 1,960
Posted By ghostdog74
if you look at the xrange() docs. it says "returns an ``xrange object'' instead of a list"
if you want to use xrange(). use a for loop

for i in xrange(1,5):.....
Forum: Python Sep 29th, 2006
Replies: 4
Solved: int2byte
Views: 1,084
Posted By ghostdog74
it's best if you could explain what you wish to do, give sample input and output if possible
Forum: Python Sep 29th, 2006
Replies: 3
Views: 1,959
Posted By ghostdog74
''.join(['\xc7', 'g', '\xea'])
Forum: Python Sep 24th, 2006
Replies: 9
Views: 1,776
Posted By ghostdog74
Does all the lines you want end in "BANK"?
Forum: Python Sep 21st, 2006
Replies: 20
Views: 7,614
Posted By ghostdog74
I assume you are working on win32 platform
if you have the win32 module, there is an example demo called win32netdemo.py and inside the source, there is a function call ServerEnum(). You can take a...
Forum: Python Sep 20th, 2006
Replies: 6
Views: 3,537
Posted By ghostdog74
....
dec = e.decode('string_escape').decode('utf8')
for i in dec: print ord(i),
...
Forum: Python Sep 19th, 2006
Replies: 6
Views: 3,537
Posted By ghostdog74
you could try this:


>>> a = unichr(275).encode('utf8')
>>> b = a.decode('utf8')
>>> b
u'\u0113'
>>> ord(b)
275
Forum: Python Sep 19th, 2006
Replies: 20
Views: 7,614
Posted By ghostdog74
thanks..yes i know.
I was giving an example on his first post.. doc and txt files. :)
Showing results 1 to 40 of 45

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC