Re: appending key-value pairs to a dict
- From: Peter Hansen <peter@xxxxxxxxxxx>
- Date: Fri, 20 May 2005 16:12:17 -0400
rbt wrote:
I know how to setup an empty list and loop thru something... appending to the list on each loop... how does this work with dicts?
I'm looping thru a list of files and I want to put the file's name and its sha hash into a dict on each loop.
Whereas with a list you would call "append" in the loop, with a dictionary you simply use an indexed-assignment type of access:
mydict = {}
for filename in some_list_of_filenames:
hash = sha.sha(open(filename).read()).hexdigest() # or whatever
mydict[filename] = hash-Peter .
- Follow-Ups:
- Re: appending key-value pairs to a dict
- From: rbt
- Re: appending key-value pairs to a dict
- References:
- appending key-value pairs to a dict
- From: rbt
- appending key-value pairs to a dict
- Prev by Date: Re: buffer_info error
- Next by Date: Re: Is Python suitable for a huge, enterprise size app?
- Previous by thread: appending key-value pairs to a dict
- Next by thread: Re: appending key-value pairs to a dict
- Index(es):
Relevant Pages
|