Skip to content

Commit

Permalink
Implement a dictionary of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Dec 30, 2019
1 parent 9b83ff9 commit 358cffc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion opy
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import re
import codecs
from collections import defaultdict

__version__ = "2.2.10"
__version__ = "2.3.0"
__author__ = "Ryuichi Ueda"
__license__ = "MIT license"
__url__ = "https://github.com/ryuichiueda/opy"
Expand Down Expand Up @@ -401,6 +401,7 @@ if __name__ == "__main__":
FNR = 0
D = defaultdict(int) #general purpose distionary
L = [] #general purpose list
K = defaultdict(list) #general purpose key & list

# The modules after -m option are imported here.
if __modules != "":
Expand Down
5 changes: 5 additions & 0 deletions test
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ com=./opy
[ "$result" = "['a', 'aa', 'aaa']" ]
}

@test "general purpose key values" {
result=$( echo -e 'a 2\nb b\na c\nb 10.0' | $com '{K[F1].append(F2)};E:{p_(K)}' | xargs )
[ "$result" = "a [2, c] b [b, 10.0]" ]
}

@test "print dictionary by p_" {
result=$( seq 3 | $com '{D[NR]="a"*F1};E:{p_(D,"@")}' )
[ "$result" = "1 a@2 aa@3 aaa@" ]
Expand Down

0 comments on commit 358cffc

Please sign in to comment.