
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Articles - Page 961 of 1048

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, index slicing can exclude specific elements when needed. Conversion to a List Applying Tuple Conversion Slicing Conversion to a ... Read More

364 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. Unicode String A Unicode string in Python tuple refers to a tuple containing Unicode string values or a string that includes a tuple with Unicode characters. Tuple with Unicode string Unicode string representing a tuple ... Read More

376 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. Non-literal Tuple Literal Tuple Non-Literal Tuple A non-literal tuple in Python is created dynamically using code instead of being written directly with parentheses and values like (2, 4, 6). # From a list data = [2, 4, 6] t = tuple(data) print(t) # From a generator t = tuple(i for i in range(3)) # ... Read More

309 Views
Immutable Vector in Python An immutable vector in Python is a fixed, ordered collection of numerical values that cannot be changed after creation. These are implemented using a tuple or libraries like immutable arrays, which specify data consistency, preventing modifications during computations. Representing Immutable Vectors Immutable vectors can be represented using tuples, which define ordered and unchangeable values. Alternatively, libraries like NumPy allow the creation of arrays with writable=False, making them immutable. This ensures that the vector values remain constant. Here are the methods to represent immutable vectors in Python. ... Read More

778 Views
A tuple is an ordered, immutable sequence of elements. In Python, the grouping of elements in a tuple list based on the values of their second elements can be done using various methods like using a dictionary or using itertools.groupby() method and using defaultdict from collections. Grouping the first elements by second elements in the Tuple list means the tuple having the same second element can be grouped into a single group of elements. In this article, we will discuss how we can implement these methods so that we are able to easily group the first elements based on ... Read More

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. example>>> a = (1, 2, 3) >>> b = (1, 2, 5) >>> a < b TrueThere is another type of comparison that takes into account similar and different elements. This can be performed using sets. Sets will take the tuples and take only unique values. Then you can perform a & operation that ... Read More

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. Tuple to Array Conversion Using Python The Python NumPy library provides various methods to create manipulate and modify arrays in Python Following are the two important methods that helps us to convert a tuple into an array − Using numpy.asarray() method Use numpy.array() method If you haven't already installed NumPy on your system, run the following ... Read More

506 Views
In Python, especially in situations like iterating through data structures, working with built-in functions, or fetching records from a database, lists of tuples are returned by the pre-defined functions instead of a list of lists. This is because tuples are immutable i.e., we cannot modify them after creation, whereas lists are mutable; once obtained, we can change their contents. This makes tuples ideal for storing fixed data like database records or function results, ensuring data integrity. Let us see methods/functions in Python that return a list of tuples - The enumerate() Function The enumerate() function is used to add a counter to ... Read More

413 Views
There is no concept of a tuple in the JSON format. Python's JSON module converts Python tuples to JSON lists because that's the closest thing in JSON to a tuple. Immutability will not be preserved. If you want to preserve them, use a utility like a pickle or write your own encoders and decoders.If you're using pickle, it won't store the Python temples in JSON files but in pkl files. This isn't useful if you're sending data across the web. The best way is to use your own encoders and decoders that will differentiate between lists and tuples depending on ... Read More

1K+ Views
In Python, a list is a mutable data type used to store a collection of items, which are separated by commas and enclosed within square brackets [ ]. According to the Python documentation, there is no concept of a homogeneous list in Python. However, a Python list can contain collections of homogeneous items, meaning that the data types of the items are the same. Python List of Homogeneous Data A Python list can contain both homogeneous and heterogeneous data. Example Here is an example of a list containing homogeneous data - # List containing ... Read More