enumerate

How to iterate initialized enumerated types with Delphi 6 and avoid the “out of bounds” error?

两盒软妹~` 提交于 2019-12-08 17:32:29
问题 I am using Delphi 6 Professional. I am interfacing with a DLL libraty that declares an enumberated type as follows: TExtDllEnum = (ENUM1 = $0, ENUM2 = $1, ENUM3 = $2, ENUM4 = $4, ENUM5 = $8, ENUM6 = $10); As you can see the initialized values are not contiguous. If I try to iterate the type using a for loop as follows: var e: TExtDllEnum; begin for e := Low(TExtToDllEnum) to High(TExtToDllEnum) do ... // More code end; Delphi still increments e by 1 each loop invocation and thereby creates

Iterate over numpy matrix of unknown dimension

怎甘沉沦 提交于 2019-12-07 16:39:19
问题 I have a multidimensional numpy array I'd like to iterate over. I want to be able to access not only the values, but also their indices. Unfortunately, for idx,val in enumerate(my_array): doesn't seem to work when my_array is multidimensional. (I'd like idx to be a tuple). Nested for loops might work, but I don't know the number of dimensions of the array until runtime, and I know it's not appropriate for python anyway. I can think of a number of ways to do this (recursion, liberal use of the

Getting driver files for a particular device

梦想的初衷 提交于 2019-12-07 04:49:22
问题 I would like to know how I can get all the driver files for a particular device just like the Device Manager does? I have the following code: procedure TdlgMain.Test(const DeviceIndex: Integer); var PnPHandle: HDEVINFO; DevData: TSPDevInfoData; DeviceInterfaceData: TSPDeviceInterfaceData; FunctionClassDeviceData: PSPDeviceInterfaceDetailData; Success: LongBool; Devn: Integer; BytesReturned: DWORD; SerialGUID: TGUID; begin ZeroMemory(@DevData, SizeOf(SP_DEVINFO_DATA)); DevData.cbSize := SizeOf

Enumerate records sequentially, grouped and by date, in MySQL

北战南征 提交于 2019-12-06 11:14:29
问题 This seems like such a simple question and I terrified that I might be bashed with the duplicate question hammer, but here's what I have: ID Date 1 1/11/01 1 3/3/03 1 2/22/02 2 1/11/01 2 2/22/02 All I need to do is enumerate the records, based on the date, and grouped by ID ! As such: ID Date Num 1 1/11/01 1 1 3/3/03 3 1 2/22/02 2 2 1/11/01 1 2 2/22/02 2 This is very similar to this question, but it's not working for me. This would be great but it's not MySQL. I've tried to use group by but

Adding column in CSV python and enumerating it

主宰稳场 提交于 2019-12-06 05:09:18
问题 my CSV looks like John,Bomb,Dawn 3,4,5 3,4,5 3,4,5 I want to add ID column in front like so: ID,John,Bomb,Dawn 1,3,4,5 2,3,4,5 3,3,4,5 using enumerate function, but I don't know how. Here's my code so far: import csv with open("testi.csv", 'rb') as input, open('temp.csv', 'wb') as output: reader = csv.reader(input, delimiter = ',') writer = csv.writer(output, delimiter = ',') all = [] row = next(reader) row.append('ID') all.append(row) count = 0 for row in reader: count += 1 while count: all

How to enumerate the strings of a context-free grammar?

点点圈 提交于 2019-12-06 03:59:39
问题 What algorithm do you use to enumerate the strings generated by a context-free grammar? It seems doable when there is no recursion, but I can't figure out how to do it in the general case, which might contain all kinds of (possibly indirect) recursion. (I'm not looking for an esoteric solution like the one on this page; I'm looking for an algorithm that I could map to standard imperative code.) 回答1: Here's an obvious but somewhat inefficient algorithm: Construct R, the Earley parser for the

How to enumerate a slice using the original indices?

点点圈 提交于 2019-12-05 22:16:27
问题 If I want to enumerate an array (say for a map() function where I would need to use the index of an element together with its value), I could use enumerate() function. E.g.: import Foundation let array: [Double] = [1, 2, 3, 4] let powersArray = array.enumerate().map() { pow($0.element, Double($0.index)) } print("array == \(array)") print("powersArray == \(powersArray)") // array == [1.0, 2.0, 3.0, 4.0] // powersArray == [1.0, 2.0, 9.0, 64.0] <- As expected Now, if I want to use some sub

Iterate over numpy matrix of unknown dimension

帅比萌擦擦* 提交于 2019-12-05 21:39:49
I have a multidimensional numpy array I'd like to iterate over. I want to be able to access not only the values, but also their indices. Unfortunately, for idx,val in enumerate(my_array): doesn't seem to work when my_array is multidimensional. (I'd like idx to be a tuple). Nested for loops might work, but I don't know the number of dimensions of the array until runtime, and I know it's not appropriate for python anyway. I can think of a number of ways to do this (recursion, liberal use of the % operator), but none of these seem very 'python-esque'. Is there a simple way? I think you want

Read csv, then enumerate

梦想的初衷 提交于 2019-12-05 14:09:34
At the moment, I have a list directly in my code and am using enumerate so I can use the list index numbers for the user to select one of the items. Looks like this (just header row included) fmpList = [['Date', 'ID', 'Plot No', 'Modified', 'Lat', 'Long']...... for item in enumerate(fmpList[]): print "[%d] %s" % item This works well but I don't want to put the list in the function but rather to read the csv from file. The alternative I used to do this is... import csv with open ('fmpList.csv', 'rU') as csvfile: next (csvfile, None) plotlist = csv.reader(csvfile, delimiter=',', dialect=csv

Python enumerate reverse index only

前提是你 提交于 2019-12-04 16:02:09
问题 I am trying to reverse the index given by enumerate whilst retaining the original order of the list being enumerated. Assume I have the following: >> range(5) [0, 1, 2, 3, 4] If I enumerate this I would get the following: >> list(enumerate(range(5))) [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)] However I want to reverse the index provided by enumerate so that I get: [(4, 0), (3, 1), (2, 2), (1, 3), (0, 4)] So far I have the following code: reversed(list(enumerate(reversed(range(5))))) I was just