FAQ  •  Login

New user working through riddles

Moderators: UncleTimmy, mjpieters

Enjoying the challenge? Need a hint?
Make a donation and help keep the site running! -thesamet
<<

elementeffect

Posts: 2

Joined: Thu Nov 04, 2010 8:10 pm

Post Thu Nov 04, 2010 8:14 pm

New user working through riddles

Hey, I am somewhat new to Python programming, and I felt like these riddles are good challenges to get some practice, but I seem to be having trouble with a piece of code I wrote to try and find the rarest characters in a huge list. Now as far as I can see, it should work. (but then again, I'm new at this. ) If you could take a look at it and give me any suggestions. Thanks


#Function to remove characters from a string
def remove(str, char):
alist= str.split()
while char in alist:
alist.remove(char)
str=''.join(alist)
return str


dct={}

code=raw_input('Input Code ->')

num=int(len(code))
while num > 0:
a=min(code)
b=code.count(a)
dct[a]=b
code= remove(code,a)
num=int(len(code))

print dct
<<

elementeffect

Posts: 2

Joined: Thu Nov 04, 2010 8:10 pm

Post Thu Nov 04, 2010 8:17 pm

Re: New user working through riddles

Sorry, last message didnt show proper indentation.


  Code:
#Function to remove characters from a string
def remove(str, char):
    alist= str.split()
    while char in alist:
        alist.remove(char)
    str=''.join(alist)
    return str
   

dct={}

code=raw_input('Input Code ->')

num=int(len(code))
while num > 0:
    a=min(code)
    b=code.count(a)
    dct[a]=b
    code= remove(code,a)
    num=int(len(code))

print dct

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.