Skip to main content

Command Palette

Search for a command to run...

Working With Python Built-in Data Structures On COLAB

Updated
1 min read
Working With Python Built-in Data Structures On COLAB
M

Mohamad's interest is in Programming (Mobile, Web, Database and Machine Learning). He is studying at the Center For Artificial Intelligence Technology (CAIT), Universiti Kebangsaan Malaysia (UKM).

Python provides four built-in data structures that are useful for data processing in Colab:

  • List
  • Tuple
  • Set
  • Dictionary The

List

List is an ordered collection of mutable items (mutable=can be modified). It is the most versatile Python data structure (able to adapt or be adapted to many different functions or activities).

listTweetMessage=[[
    1600431822978322437,
    'Big Data',
    'Thursday, December 1, 2022 12:00:00 AM'
]]

Tuple

Tuple is an ordered collection of immutable items (immutable=cannot be modified). As tuples are immutable, they are faster than the list because they are static.

tuplTweetMessage=[(
    1600431822978322437,
    'Big Data',
    'Thursday, December 1, 2022 12:00:00 AM'
)]

Set

Set is an unordered collection of unique immutable items. Set is useful to be used as a lookup table.

setMediaType={
    'text',
    'image',
    'video',
    'audio',
    'pdf'
}

Dictionary

Dictionary is a type of key-value pairs collection where keys are unique and values are mutable items.

dictCountry={
    'uk':'United Kingdom',
    'sp':'Spain',
    'it':'Italy'
}

Further reading:

  • https://www.javatpoint.com/python-lists
  • https://www.tutorialspoint.com/python/python_lists.htm
  • https://realpython.com/python-lists-tuples/
  • https://www.pythoncheatsheet.org/blog/python-sets-what-why-how
25 views