deleting unnecessary chars?

This is the place for queries that don't fit in any of the other categories.

Re: deleting unnecessary chars?

Postby Mekire » Tue Sep 03, 2013 11:55 am

All of the info is up there.

Code: Select all
def clean_garbage(string,accepts):
    letter_list = [letter for letter in string if letter in accepts]
    return "".join(letter_list)

def no_duplicates(string):
    result = []
    for word in string.split():
        if word not in result:
            result.append(word)
    return " ".join(result)


if __name__ == "__main__":
    my_input = input("Enter you string: ")
    cleaned = clean_garbage(my_input,"ABCD ")
    no_dups = no_duplicates(cleaned)
    print(cleaned)
    print(no_dups)
Code: Select all
>>>
Enter you string: "AB$%@C#D A^B AdfhCa $%ACD A@@@BCD"
ABCD AB AC ACD ABCD
ABCD AB AC ACD
>>>
User avatar
Mekire
 
Posts: 814
Joined: Thu Feb 07, 2013 11:33 pm
Location: Amakusa, Japan

Re: deleting unnecessary chars?

Postby el_manu » Thu Sep 05, 2013 12:57 pm

Would my code do the same thing...

Code: Select all
def get_rid_of_extra_characters(string,accepts):
    letter_list = [letter for letter in string if letter in accepts]
    return "".join(letter_list)
if __name__ == "__main__":
    retarted = input("Enter something: ")
    Removed_junk = get_rid_of_extra_characters(retarted,"ABCD ")
words = Removed_junk.split()
print(Fixed:', " ".join(sorted(set(words), key=words.index)))

#BIBLIOGRAPHY - to help me use the def and main functions


#http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm
#http://www.artima.com/weblogs/viewpost.jsp?thread=4829

#And to stop duplicates

#http://stackoverflow.com/questions/7794208/python-remove-duplicate-words-in-string
el_manu
 
Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Re: deleting unnecessary chars?

Postby Kebap » Thu Sep 05, 2013 1:10 pm

Talking about chars, the words "retarded" and "retard" actually use a d instead of t at the end. ;)
Learn: How To Ask Questions The Smart Way
Join the #python-forum IRC channel on irc.freenode.net and chat with uns directly!
Kebap
 
Posts: 282
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Re: deleting unnecessary chars?

Postby micseydel » Fri Sep 06, 2013 4:33 am

el_manu: I am going to delete without warning all future posts in which you use offensive language. If you're not sure if something would be offensive, then think for a second about why you weren't sure, and what that might mean.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 923
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: deleting unnecessary chars?

Postby el_manu » Fri Sep 06, 2013 9:27 am

sorry for that.
el_manu
 
Posts: 87
Joined: Mon Aug 19, 2013 8:30 am

Previous

Return to General Coding Help

Who is online

Users browsing this forum: Cereal, DrakeMagi and 7 guests