[Tutor] comapring lists

Max Noel maxnoel_fr at yahoo.fr
Mon Nov 29 18:27:05 CET 2004


On Nov 16, 2004, at 04:39, Jim De Caro wrote:

> I am getting user input and comparing it to an iterated list.  I can 
> get the
> input to print out verbatim.  I want to then "swap" individual letters 
> in the
> input with letters from a second list so it is like a simple 
> encryption.  I
> can't figure out the correct logic or syntax.  Here is what I have so 
> far:
>
> [SNIP]
> This does not work.  Any suggestions?

	My first impression is that you should use a dictionary to do that, 
where for each element the key is the unencrypted character and the 
value is the encrypted one. For example, a ROT13 encryption dictionary 
would look like {'a': 'n', 'b': 'p', 'c': 'q', [...]}.
	Then, once you have your dictionary, all you have to do is:

for i in user:
	print encryption[i]

...to get the encrypted version of your string.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list