From 76049d972942ed71ca20f3bc91106a60f5a1181f Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Mon, 6 Apr 2015 17:04:08 +0100 Subject: [PATCH] Data structures added --- Nim-for-Python-Programmers.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Nim-for-Python-Programmers.md b/Nim-for-Python-Programmers.md index c6cd272..8cc0fe2 100644 --- a/Nim-for-Python-Programmers.md +++ b/Nim-for-Python-Programmers.md @@ -108,6 +108,19 @@ That will return a compilation error, because the objects have different sizes. So, when using inheritance, be sure to inherit using refs, unless you know what you are doing. Also, check out Nim's generic programming capabilities as an alternative to OOP and inheritance. -### Structs - Tuples and Objects +## Data structures -Tuples are entirely different from Python \ No newline at end of file +### Python tuples + +Nim Tuples are close to Python nametuples, see [manual](http://nim-lang.org/manual.html#tuples-and-object-types) + +### Python sets + +Python sets are not like [Nim set type](http://nim-lang.org/manual.html#set-type). +If the values that will go in the set are known beforehand and finite, you can create an Enum for them. +Otherwise you can emulate a Python set using a [HashSet](http://nim-lang.org/sets.html). +The Nim set type is faster and memory-efficient. + +### Dictionaries + +Use [HashSet](http://nim-lang.org/sets.html)