Re: appending key-value pairs to a dict
rbt <rbt@xxxxxxxxxxxxxxxxx> 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.
You just assign values to keys. If the key doesn't exist, it's
created automagically. You want something like this:
shaDict = {}
for fileName in fileNameList:
hash = generateShaHash (fileName)
shaDict[hash] = fileName
.
Relevant Pages
- filenames with spaces and list in a for loop
... Second attempt was to double quote the "`ls -1A $1`", which generates ONE huge argument to the for loop. ... Unfortunately, the list also generates a newline every 80 characters in the $LIST, so once in a while I was left with each_item being set to something like "\nfilename". ... At the first occurrence of $each_item in the function I would get something like <filename> not found. ... what if I have a directory with more than 65000 characters worth? ... (comp.unix.shell) - Re: long running perl programs & memory untilization
... >> It does setup stuff, and then goes into a loop. ... # reads in temporary capture file adds timestamp, ... # Argument 1 is filename that the labled image should be stored as ... my $grab = $_; ... (comp.lang.perl.misc) - Re: DTS query result to file - can I loop it?
... How to loop through a global variable Rowset ... How can I change the filename for a text file connection? ... The values for @MyType are stored in a database table so a cursor ... > existing DTS package or will I have to create a new package to handle each ... (microsoft.public.sqlserver.dts) - Re: python skipping lines?
... and your first pass through this loop, you exhaust RawData by reading to the end. ... The second pass through the UnitList loop, you pass the exhausted RawData to PullHourlyData. ... I'm thinking you'd need to RawData.seekor some such "rewind" ability. ... Part of the confusion stems from the fact that what you refer to as "filename" is actually a file object that contains state. ... (comp.lang.python) - Re: Downloading multiple files
... Dim fn As Variant, f As Integer, i As Integer, counter As ... Windows.Activate 'Change the filename to match ... loop, but the last digits (time stamp) are not repeatable, as the ... (microsoft.public.excel.programming) |
|