newbie question convert C to python
Steven Bethard
steven.bethard at gmail.com
Tue Feb 15 11:03:06 EST 2005
Paul Rubin wrote:
> doodle4 at gmail.com writes:
>
>>How do i handle this piece of code in python:
>>
>># define vZero 15
>># define vOne 20
>>
>>unsigned int vTable[Zero][One]
>>
>>if(vGroup[vZero][vOne] == 0)
>> {
>> vGroup[vZero][vOne]--
>> .....
>> .....
>> }
>
> Simplest might be with a dictionary:
>
> vGroup = {} # I assume you meant vGroup not vTable
> if vGroup[(vZero, vOne)] == 0:
> vGroup[(vZero, vOne)] -= 1
> .....
> .....
Or, if you like, the parentheses are unnecessary:
vGroup = {}
if vGroup[vZero, vOne] == 0:
vGroup[vZero, vOne] -= 1
.....
This (or the semantically identical version with parentheses) is
definitely the best approach if you expect to have a lot of empty spots
in your table.
STeVe
More information about the Python-list
mailing list