help with explaining how to split a list of tuples into parts
peter at ifoley.id.au
peter at ifoley.id.au
Sat Jul 13 07:47:10 EDT 2013
On Saturday, 13 July 2013 17:28:50 UTC+10, Peter Otten wrote:
>
> Every time when you have to look up something you should think 'dict', and I
>
> expect that pretty that will happen automatically.
>
> Also, to split a tuple into its items you can "unpack" it:
>
>
>
> triple = (1, 2, 3)
>
> one, two, three = triple
>
> assert one == 1 and two == 2 and three == 3
>
>
>
> So:
>
>
>
> supported_hashes = {
>
> "crypt": (2, "", 13),
>
> "md5": (8, "$1$", 22),
>
> ...
>
> }
>
> ...
>
> parser.add_argument(
>
> '--hash', default='sha512',
>
> choices=supported_hashes, # accept the keys
>
> help='Which Hash function to use')
>
> ...
>
> salt_length, hash_type, expected_password_length = supported_hashes[args.hash]
>
> ...
Hi Peter,
Thanks for the pointers I will try your suggestion out and read some more.
Peter.
More information about the Python-list
mailing list