User Profile

Collapse

Profile Sidebar

Collapse
kdt
kdt
Last Activity: Aug 4 '08, 11:02 PM
Joined: Mar 31 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • kdt
    replied to type conversion problem
    sorry I gave the wrong info

    x=1234...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to type conversion problem
    thanks for the reply

    I'm summing the squares of elements in a list

    Code:
    x=[1, 2, 3]
    
    # I would expect 14 as a result
    cheers
    See more | Go to post

    Leave a comment:


  • kdt
    started a topic type conversion problem

    type conversion problem

    hi all,

    I've just started back up with python after a looong break - it's great to be back :D

    Anyway, I'm going through "how to think like a computer scientist" as a refresher and trying to come up with a function to return the sum of squares for a given number.

    I decided to write it as a list comprehension:
    Code:
    sum(int(i)**2 for i in str(x))
    I think I read somewhere...
    See more | Go to post

  • kdt
    replied to wxPython crashes when run
    Thanks Bartonc, resolved now. :)...
    See more | Go to post

    Leave a comment:


  • kdt
    started a topic wxPython crashes when run

    wxPython crashes when run

    Hi,

    My GUI keeps crashing on the second time it runs. It doesn't come up with any useful error messages, just says "there was a problem". I've narrowed the offending code to the following.

    I'm running wxpython on windows xp.

    cheers

    [CODE=python]

    import wx

    class myFrame(wx.Fram e):
    def __init__(self, parent, id, title):
    wx.Frame.__init __(self,...
    See more | Go to post

  • kdt
    replied to 'float' / 'int' object is not iterable
    If you want to avoid the use of recursion you can use the following. The factorial is calculated using a while loop, and the summation by a for loop. :

    [CODE=python]

    >>> def factorial(n):
    f=1
    while(n>0):
    f*=n # same as f=f*n, just faster
    n-=1# same as n=n-1
    return f

    >>> def summation(k, limit):
    sigma=0
    for i in range(k, limit+1):...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to help with object method calls
    Thanks bvdet, was struggling with this yesterday. There's an extra '-1' in your code, but apart from that, it works fine. The only obscurity is having to pass two parameters for the factorial method - although I understand that this is required for it to be able to be called from the binomail method. Is it better practice to keep it like this, or should it be left in functions? Just looking for an opinion here, still a newb so want to learn the best...
    See more | Go to post

    Leave a comment:


  • kdt
    started a topic help with object method calls

    help with object method calls

    Hi,

    Been reading about objects today. I have a program, that I am trying to rewrite as much as possible as objects. I want to write the following two functions as methods in the Number class:

    [CODE=python]
    def factorial(n):
    '''
    n is a positive integer;
    RETURNS: integer factorial of n from a recursive function.
    '''
    f = 1
    while (n > 0):
    ...
    See more | Go to post

  • kdt
    replied to return top results from list
    sorry, please disregard my last post, I was being silly again - passing the wrong values to the function. All's good now

    Thanks
    See more | Go to post
    Last edited by kdt; Sep 19 '07, 01:46 PM. Reason: too long

    Leave a comment:


  • kdt
    replied to return top results from list
    Thanks bvdet, definately more concise than my attempt. Had to make some slight changes to it to get the output I wanted. However, there is a really strange property of it, in it that it doesn't return the top topx results, instead it will only return the top 1 for each position regardless of the value of topx. You can however add y to topx where y = top number of results you want -1. Strange indeed!

    [CODE=python]
    def positionalWeigh ts(dd,topx...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to return top results from list
    Thanks mate, it looks like the speed issue is from another part of the program. I'll definately use parts of this (especially for learning, I need to use try: except more) :)...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to return top results from list
    cheers mate, made quite a few mistakes in this one. Finally got it working now- yipee! Still if anyone can propose speed tips, I'm using psyco, and it doesn't seem to be making much difference :S

    [CODE=python]
    def positionalWeigh ts(dd, topx=2):
    posList = [[] for i in range(9)]

    for key in dd.keys():
    for i, item in enumerate(key):
    if item != '.':
    ...
    See more | Go to post

    Leave a comment:


  • kdt
    started a topic return top results from list

    return top results from list

    Hi,

    With a list of fixed length strings, I want to count the occurrences of each characters at each of 9 positions. I then want to return the top 2 results for each position. The result has to be a list for the function I am passing this too. The code I have so far has two rather big problems (1) it is too slow and (2) it gives the wrong results :(

    [CODE=python]
    dd ={'.LEA.....':7 7,'R....L...':8 ,'.L....DA.':5, '.L.R.V..L':4,' A....S.SA':55,' QL..L....':5,'M .SC.SE..':77}...
    See more | Go to post

  • kdt
    replied to conditional statement
    excellent, i was trying to add the tag earlier, just didn't know how!

    cheers...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to conditional statement
    Hi Python101,

    I saw from another of your posts that you are either a bioinformaticia n, or working on biological data.

    Hopefully you will find some of these links useful:

    Quick intro from O'Reilly with useful examples.
    O'Reilly Python for Bioinformatics

    Beginners guide to Python aimed at Biologists from the Pasteur Institute:
    Intro Python for Biologists

    More...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to conditional statement
    Code:
    >>> str1 = 'test'
    >>> str2 = 'python'
    >>> if not str1 in str2:
    	print 'error'
    
    	
    error
    HTH...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to wordplay problem
    Thanks mate,

    Thats definately nicer :)...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to wordplay problem
    Hi,

    Managed to get this done by modifying KaezarRex's code - thanks.
    Code:
    >>> sList = [['t','v'],['y','k','l']]
    >>> patt ='..g'
    >>> def recurse(pattern, sList):
        if pattern.count('.'):
            j=pattern.find('.')
            for i in sList[j]:
                recurse(pattern.replace ('.', i,1), sList)
        else:
            print pattern
    ...
    See more | Go to post
    Last edited by kdt; Sep 17 '07, 09:29 PM. Reason: forgot code tags

    Leave a comment:


  • kdt
    replied to wordplay problem
    Hi bartonc,

    Unfortunately I need to use lists as I need to append values, as in the following (surely there's a more elegant way of doing this):

    Code:
    pos1 =[]
    pos3 =[]
    pos4 =[]
    pos5 =[]
    pos6 =[]
    pos7 =[]
    pos8 =[]
    
    for key in gOutList.keys():
        if not key[0] in pos1:
            pos1.append(key[0])
        if not key[2] in pos3:
            pos3.append(key[2])
    ...
    See more | Go to post

    Leave a comment:


  • kdt
    replied to wordplay problem
    Hi all,

    Sorry to resurrect an old post, but I have a more complex feature I need to add.
    Given some patterns such as "...t...s." I need to make all possible combinations given a separate list for each position. The length of the pattern is fixed to 9, so thankfully that reduces a bit of the complexity.

    For example I have the following:

    pos1 = ['a',' t']
    pos2 = ['r', 's']
    ...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...