The size of a dictionary Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

The size of a dictionary

06 Jul 2016, 08:37

CODE :

Code: Select all

AR := {"l" : ["A", "B", "C"], "m" : ["D", "E", "F"]}

MsgBox % AR.Length()
Why the .Length() functoin didn't return '2' ?

what I'm doing wrong !?
Guest

Re: The size of a dictionary

06 Jul 2016, 10:25

Returns the length of a linear array beginning at position 1; that is, the highest positive integer key contained by the object, or 0 if there aren't any.
- https://autohotkey.com/docs/objects/Object.htm#Length
Paneb
Posts: 54
Joined: 24 Aug 2015, 05:02
Location: France
Contact:

Re: The size of a dictionary

06 Jul 2016, 11:31

Dunno if there is easier than this, but it is working:

Code: Select all

AR := {"l" : ["A", "B", "C"], "m" : ["D", "E", "F"]}
size := 0
For key, value in AR
    size++
MsgBox % size
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: The size of a dictionary

06 Jul 2016, 12:08

I have been asking for such a thing for a while now: https://autohotkey.com/boards/viewtopic.php?f=13&t=7101
" .count() ; this is what I'd expect .length() to do, but since it doesn't, .count() could exist aswell
counts the number of items in an array or object, regardless of type ..."

feel free to post in that topic to support the idea.
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: The size of a dictionary  Topic is solved

06 Jul 2016, 20:14

Paneb wrote:Dunno if there is easier than this, but it is working:

Code: Select all

AR := {"l" : ["A", "B", "C"], "m" : ["D", "E", "F"]}
size := 0
For key, value in AR
    size++
MsgBox % size
Thank you bro ! :D
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: The size of a dictionary

06 Jul 2016, 20:16

tidbit wrote:I have been asking for such a thing for a while now: https://autohotkey.com/boards/viewtopic.php?f=13&t=7101
" .count() ; this is what I'd expect .length() to do, but since it doesn't, .count() could exist aswell
counts the number of items in an array or object, regardless of type ..."

feel free to post in that topic to support the idea.
What if i need to read the dict by Index ?

Code: Select all

AR := {"l" : ["A", "B", "C"], "m" : ["D", "E", "F"]}

MsgBox % AR["l"][1]
MsgBox % AR[1][1]
Why AR[1][1] retrieved nothing ?
Guest

Re: The size of a dictionary

06 Jul 2016, 22:15

Code: Select all

AR := {l: ["A", "B", "C"], 1: ["D", "E", "F"]}
 
MsgBox % AR["l", 1]
MsgBox % AR[1, 1]
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: The size of a dictionary

07 Jul 2016, 01:07

Guest wrote:

Code: Select all

AR := {l: ["A", "B", "C"], 1: ["D", "E", "F"]}
 
MsgBox % AR["l", 1]
MsgBox % AR[1, 1]
I'm expecting the second would retrieve "A"

First element of first key.
Guest

Re: The size of a dictionary

07 Jul 2016, 01:31

dsewq1LYJ wrote:
Guest wrote:I'm expecting the second would retrieve "A"

First element of first key.
:terms: https://autohotkey.com/docs/Objects.htm ... ive_Arrays ;)
dsewq1LYJ
Posts: 116
Joined: 26 Aug 2014, 23:21

Re: The size of a dictionary

07 Jul 2016, 03:06

Guest wrote:
dsewq1LYJ wrote:
Guest wrote:I'm expecting the second would retrieve "A"

First element of first key.
:terms: https://autohotkey.com/docs/Objects.htm ... ive_Arrays ;)
Thanks bro ! but why not I just iterate through this array by For Loop loool

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, DataLife, Google [Bot], ShatterCoder and 260 guests