[Tutor] need idea
invincible patriot
invincible_patriot at hotmail.com
Thu Feb 11 00:12:05 CET 2010
thanks
let me clear you that what i am trying to do
suppose we hav a input string and a dict
our_dict={'a':'u', 't':'a', 'c':'g', 'g':'c'}
input_string='atcg'
now what i wana do is that where ever we are having 'a' i wana replace it with 'u', 't' with 'a' and so on
i tried using input_string.replace('a', 'u')
but it is replacing only one character
i wana replace these 4 characters according to the dictionary
i hope it is now clear
kindly let me know how to proceed now
> From: andreengels at gmail.com
> Date: Wed, 10 Feb 2010 23:10:38 +0100
> Subject: Re: [Tutor] need idea
> To: invincible_patriot at hotmail.com
> CC: tutor at python.org
>
> On Wed, Feb 10, 2010 at 10:27 PM, invincible patriot
> <invincible_patriot at hotmail.com> wrote:
> > hi
> > i want to compare a string with a dictionary
> > or u can say that i want to take user input A STRING, and want to compare
> > each character of that string with the KEYS in the dictionary, and then i
> > wana print the values for the characters that are present in that strinng
> > that we got as the input and were present in the dictionary as well
> >
> > can you please give me some idea how to do that
> >
> > what i hav done is that
> > 1) I have made a dictionary with the keys and the values
> > 2) I have taken the input from the user and hav saved it into a variable
> >
> > not i wana compare string that was given to us and replace them with the
> > values given in the dictionary
>
> It's not yet completely clear to me what you want, but the following
> should help you:
>
> Let str be the string, and dict the dictionary, then:
>
> [c for c in str if c in dict]
>
> will give you the characters in the string that are keys in the dictionary.
>
>
>
>
> --
> André Engels, andreengels at gmail.com
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/201469230/direct/01/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100210/660865e3/attachment.htm>
More information about the Tutor
mailing list