Urgent.News

What's breaking now, across thousands of outlets.

Tech

lets explore data Structures in Python

Introduction Data science begins with data, and how that data is stored determines how easily it can be cleaned, explored, and analyzed. Python is a data science tool tat anyone who is interested in data science would be wise to utilize. Python's four core data structures (lists, tuples, dictionaries, and sets) form the foundation for this work. Lists hold ordered collections such as a column of…

Python is a popular programming language for data science, thanks to its versatile data structures. Four core data structures in Python include lists, tuples, dictionaries, and sets. These structures serve as the building blocks for data manipulation and analysis in Python.

Lists are one-dimensional arrays that can store elements of various types. They are mutable, meaning their contents can be altered after creation. A list is defined using square brackets, with elements separated by commas. For example, mixed_bag = [1, 2, 'bob'] creates a list containing integers, a string, and another list.

Several functions are available to modify lists. The append() function adds an element to the end of a list, while the insert() function allows adding an element at a specific index. The extend() function enables adding multiple elements at once to the end of a list.

Accessing data in a list involves indexing, where each element is assigned a unique position starting from 0. Positive indexing allows retrieving elements from the beginning of the list, while negative indexing enables accessing elements from the end, with -1 referring to the last element. Slicing allows extracting a portion of a list by specifying a start and stop index, with an optional step parameter to control the increment between selected elements.

In contrast to lists, tuples are immutable, meaning their contents cannot be changed once defined. Tuples are defined using parentheses, with elements separated by commas. Once a tuple is created, its values remain fixed, making them suitable for storing fixed data such as configuration settings or coordinates. For example, mixed_tuple = (1, 2, 'bob', 3) creates a tuple containing mixed data types.

Similar to lists, tuples also support indexing and slicing operations. Just like lists, tuples can be indexed using positive and negative numbers, with negative indexing allowing access from the end of the tuple. Slicing in tuples functions similarly to lists, enabling the extraction of specific sections of the tuple using start, stop, and step values.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

This story

This is one outlet's version. Read the fullest account.

Read the original at dev.to →

More in Tech

Building FoxyInvoice — Chapter 4: Multi-tenancy & data security — the vault

This series is written in the open, from a real production system. This chapter is the vault: identity, isolation, authorization, and the tests that prove it holds.

  • Multi-tenancy allows unrelated companies to share one system with isolated data.
  • Identity established via email/password, Google SSO, and JWT access tokens.
  • Isolation achieved through EF Core query filters, save interceptor, and CI tests.

More from Sunday 20 September →