Articles on Trending Technologies

Technical articles with clear explanations and examples

How to convert python tuple into a two-dimensional table?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 2K+ Views

A tuple in Python is an ordered, immutable collection that stores multiple items. Converting tuples into two-dimensional tables helps organize data in a structured, tabular format for better analysis and visualization. What is a Two-Dimensional Table? A two-dimensional table is a data structure organized in rows and columns, similar to a spreadsheet. Each row represents a record, and each column represents a specific property or field. Example Table Structure NAME AGE CITY Ramesh 32 Hyderabad Suresh 42 Bangalore Rajesh 52 Chennai Here's how to create ...

Read More

How can I represent python tuple in JSON format?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 28K+ Views

Python tuples can be represented in JSON format as arrays. Since JSON doesn't have a native tuple type, Python's json module automatically converts tuples to JSON arrays, preserving the data while changing the structure slightly. What is JSON? JSON (JavaScript Object Notation) is a lightweight, human-readable data interchange format. While derived from JavaScript, it works as a language-independent text format compatible with Python and many other programming languages. JSON facilitates data exchange between servers and web applications. JSON is composed of two main structures: Name/value pairs (like objects or dictionaries) Ordered collections of values (like ...

Read More

How can I remove items out of a Python tuple?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 2K+ Views

A tuple in Python is an ordered, immutable collection that holds multiple items, supports mixed data types, and allows indexing. Since tuples cannot be modified directly, we need special techniques to remove items from them. Here are three main approaches to remove items from a Python tuple: Converting to List and Back Using Tuple Comprehension ...

Read More

How can I create a Python tuple of Unicode strings?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 467 Views

A tuple in Python is an ordered, immutable collection that stores multiple items. It supports mixed data types, allows indexing, and is commonly used for fixed data structures. In Python 3, all strings are Unicode by default, making it straightforward to create tuples containing Unicode strings. Creating Basic Unicode String Tuples You can create a tuple with Unicode strings by simply placing Unicode text inside tuple parentheses. Python 3 handles Unicode automatically ? # Basic Unicode tuple unicode_tuple = ('café', 'naïve', '世界', '😊') print(unicode_tuple) print(type(unicode_tuple)) ('café', 'naïve', '世界', '😊') Using ...

Read More

How can I create a non-literal python tuple?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 451 Views

A tuple in Python is an ordered, immutable collection that stores multiple items. Tuples can be created in two ways: directly with fixed values (literal) or dynamically using code (non-literal). Literal Tuple − Created directly with parentheses: (1, 2, 3) Non-literal Tuple − Created dynamically using functions or expressions What is a Non-Literal Tuple? A non-literal tuple is created dynamically using code instead of being written directly with parentheses and values. It's formed through functions, expressions, or data transformations. Method 1: Using tuple() Constructor Convert existing data structures into tuples ? ...

Read More

How can I represent immutable vectors in Python?

Sindhura Repala
Sindhura Repala
Updated on 24-Mar-2026 417 Views

An immutable vector in Python is a fixed, ordered collection of numerical values that cannot be changed after creation. These are implemented using tuples or libraries like NumPy with write protection, ensuring data consistency and preventing modifications during computations. Methods to Represent Immutable Vectors Python provides several approaches to create immutable vectors ? Using Tuples Using NumPy Arrays with Write Protection Using Named Tuples Using Tuples Tuples are inherently immutable in Python, making them ideal for representing fixed vectors ? ...

Read More

How do we compare two tuples in Python?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 24-Mar-2026 6K+ Views

Tuples are compared position by position: the first item of the first tuple is compared to the first item of the second tuple; if they are not equal, this is the result of the comparison, else the second item is considered, then the third and so on. Lexicographic Comparison Python compares tuples element by element from left to right using lexicographic ordering ? a = (1, 2, 3) b = (1, 2, 5) print(a < b) print(a == b) print(a > b) True False False In this example, the first two ...

Read More

How can I convert Python tuple to C array?

Vikram Chiluka
Vikram Chiluka
Updated on 24-Mar-2026 10K+ Views

In this article, we will show you how to convert a Python tuple to a C array. Python does not have a built-in array data type like other programming languages, but you can create an array using a library like NumPy. Installation If you haven't already installed NumPy on your system, run the following command to do so ? pip install numpy Methods for Tuple to Array Conversion The Python NumPy library provides various methods to create, manipulate and modify arrays in Python. Following are the two important methods that help us convert ...

Read More

Why python returns tuple in list instead of list in list?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 630 Views

In Python, many built-in functions and operations return lists of tuples instead of lists of lists. This design choice is intentional and serves important purposes in data integrity and performance. The primary reason is that tuples are immutable − once created, they cannot be modified. This makes them ideal for representing fixed data like database records, coordinate pairs, or grouped values that should remain unchanged. In contrast, lists are mutable and can be accidentally modified, which could lead to data corruption. The enumerate() Function The enumerate() function adds a counter to an iterable and returns an enumerate ...

Read More

How can I preserve Python tuples with JSON?

Samual Sam
Samual Sam
Updated on 24-Mar-2026 478 Views

JSON format doesn't have a built-in tuple type, so Python's json module converts tuples to JSON arrays (lists). This means the immutability of tuples is lost during serialization. However, you can preserve tuples using custom encoders and decoders or alternative serialization methods. Problem: Default JSON Conversion By default, Python tuples are converted to JSON arrays ? import json data = { "coordinates": (10, 20), "colors": ["red", "blue"], "dimensions": (1920, 1080, 32) } json_string = json.dumps(data) print("JSON string:", json_string) # When loaded ...

Read More
Showing 1–10 of 61,302 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements