help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Octave and Database connectivity


From: fork
Subject: Re: Octave and Database connectivity
Date: Mon, 24 Sep 2012 17:12:03 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Jordi Gutiérrez Hermoso <jordigh <at> octave.org> writes:

> 
> On 22 September 2012 07:01, Sergei Steshenko <sergstesh <at> yahoo.com> wrote:
> > But isn't Octave's struct an equivalent of Python's dict functionality ?
> 
> Sort of. You can only use strings as keys in a struct. You can use any
> hashable type in Python as keys.

Also, Python's dict is built into the syntax, which can make certain operations
a lot more elegant.  For example, counting words with a dict in python (assuming
words in a list, untested, probably could shorten with ifelse() ):

for word in words:
    cdict[word] += 1

Counting words the same in Octave (words in a 1xN cell array, untested):

for word in words
    if isfield(cstruct, word)
        cstruct = setfield(cstruct, word, getfield(cstruct, word)+1))
    else 
        cstruct = setfield(cstruct, word, 1)
    endif
endfor

dicts would go in my list of things for octaveng (ng = next generation), along
with reference syntax for pass by reference, and named parameters, and python
style classes.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]