Difference between revisions of "Python-datastructures"

From wikipost
Jump to navigationJump to search
Line 15: Line 15:
 
|style="background-color:#f2f2f2;"|<b>Examples</b>
 
|style="background-color:#f2f2f2;"|<b>Examples</b>
 
|style="background-color:#f2f2f2;"|<b>Details</b>
 
|style="background-color:#f2f2f2;"|<b>Details</b>
 +
|style="background-color:#f2f2f2;"|<b>Characteristic</b>
 
|-
 
|-
 
|Tuple
 
|Tuple
Line 21: Line 22:
 
|Once set, values cannot be changed
 
|Once set, values cannot be changed
 
Referenced with index
 
Referenced with index
 +
|surrounded by one single open and closed parenthesis
 
|-
 
|-
 
|List
 
|List
Line 27: Line 29:
 
|Values can be modified, added, deleted
 
|Values can be modified, added, deleted
 
Referenced with index
 
Referenced with index
 +
|surrounded by one single open and closed square bracket
 
|-
 
|-
 
|Dictionary
 
|Dictionary
Line 33: Line 36:
 
|Values can be modified, added, deleted
 
|Values can be modified, added, deleted
 
Referenced with a key
 
Referenced with a key
 +
|surrounded by one single open and closed curly brace
 
|-
 
|-
 
|Set
 
|Set
Line 42: Line 46:
  
 
Unordered
 
Unordered
 +
|single square brackets surrounded by single parenthesis
 +
values separated by a comma
 
|-
 
|-
 
|json
 
|json
Line 47: Line 53:
 
|Values can be modified, added, deleted
 
|Values can be modified, added, deleted
 
Referenced with a key
 
Referenced with a key
 +
|surrounded by one single open and closed square bracket
 
|-
 
|-
 
|csv
 
|csv
 
|x
 
|x
 
|y
 
|y
 +
|values separated by a comma
 
|}
 
|}

Revision as of 08:04, 23 December 2020

"In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data."

-- source: Wikipedia


Python knows how to work with of several types of data structures without the need to import additional libraries. Sometimes you do need to import a library to provide support (e.g. json, csv, sql) but most of these are already available when you have python installed. In rare cases you may need to build or acquire a third-party library for data structure support.


In these pages we mainly look at the most common data structures in python:


Name Examples Details Characteristic
Tuple ('January', 'February', 'March', 'April', 'May')

(2, 3, 5, 7, 11, 13, 17, 19, 23, 29)

Once set, values cannot be changed

Referenced with index

surrounded by one single open and closed parenthesis
List [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

['red', 'green', 'orange', 'blue']

Values can be modified, added, deleted

Referenced with index

surrounded by one single open and closed square bracket
Dictionary {'Joe':02079343, 'Alice':010534045, 'Bob':01084523}

{'x':234, 'y':345, 'z':456}

Values can be modified, added, deleted

Referenced with a key

surrounded by one single open and closed curly brace
Set ([1029, 1238, 7821, 4312, 2716]) Once set, values cannot be modified

Set values can be added and removed

Set may only contain unique values

Unordered

single square brackets surrounded by single parenthesis

values separated by a comma

json x Values can be modified, added, deleted

Referenced with a key

surrounded by one single open and closed square bracket
csv x y values separated by a comma