Most voted "tuple" questions
In Python tuples are a data structure that function as a list, but are immutable.
Learn more…52 questions
Sort by count of
-
24
votes1
answer9723
viewsWhat is Tuple and when to use?
I saw the use in a site and I was left with the doubt of what is Tuple, and when should I use in my project?
-
15
votes3
answers10708
viewsWhat is the main difference between a Tuple and a List?
What are the differences between a Tuple and a List in the Python? Example: >a = [1, 2, 3] # [1, 2, 3] >b = (1, 2, 3) # (1, 2, 3) The Tuple, grotesquely speaking, it is a constant that accepts…
-
11
votes2
answers199
viewsWhat are the deconstructors?
When studying about Records in C# 9 was filed the appeal Deconstruct() where the object is assigned to a Tuple. What is a Deconstruct()? Does it remove the reference of the object causing it to…
-
9
votes1
answer4345
viewsHow to sort a list of tuples by the nth element?
I have a list of fashion tuples: [(0, 1), (2, 3), (4, -5), (6, -3)] I want to sort that list by the second value of each tuple (i.e., in case we would [(4, -5), (6, -3), (0, 1), (2, 3)]. How to do…
-
9
votes2
answers228
viewsIs Tuple the same as creating an object?
I’ve used the Tuple a few times and today came the doubt, that: public class User{ public String Name {get; set;} public String LastName {get; set;} } new User(){ Name = "Leonardo", LastName =…
-
9
votes2
answers228
viewsIs Tuple the same as creating an object?
I’ve used the Tuple a few times and today came the doubt, that: public class User{ public String Name {get; set;} public String LastName {get; set;} } new User(){ Name = "Leonardo", LastName =…
-
7
votes1
answer13017
viewsTuples in a database
I know what a Python tuple is but not in a database, so follow the question: What is a tuple in the database context?
-
7
votes1
answer891
viewsIs it possible to unstructure an array in PHP equal to or similar to the Python list?
In Python we can unstructure a list like this: lista = [ "Maça", "Pera" ] maca, pera = lista print(maca, pera) the exit will be: Maça Pera I know that in PHP it is possible to get the result using…
-
6
votes1
answer1909
views -
5
votes3
answers392
viewsWhy in Python can we define an index of a Dict as a Tuple?
I noticed that in Python, we can add values like tuple as an index of a dict (dictionary). Example: test = {} test[(1, 2, 3)] = ("um", "dois", "tres") print test // {(1, 2, 3): ('um', 'dois',…
-
5
votes1
answer10433
viewsWhat is the difference between Sorted() and . Sort()?
Why the function sorted() is considered more direct than the method .sort() used in lists with tuples?
-
4
votes2
answers223
viewsIs there a performance difference between Tuple and List?
In Python, I know there’s a difference between Tuple and a List. To Tuple is immutable, and the List, mutable. You even have that question here: What is the main difference between a Tuple and a…
-
3
votes2
answers991
viewsDo word search inside a list and return tuples sorted in PYTHON
The algorithm should receive a string, count how many words equal and return a list of tuples with the words that most appear in the string and how many times it appears. The problem is that in…
-
3
votes1
answer1815
viewsDifferences between list, tuple and set
I know that in Python there are three structures that apparently resemble each other, but that in the background there are differences. They are: list, tuple and set. List a = [1, 2, 3, 4] Tuple a =…
-
3
votes4
answers167
viewsHow to return the first vowel of several words in a list?
The code is partially done, but it returns only the vowels found in each word. How could I return only the first vowel of each word? palavras = ('boi', 'vaca', 'macaco', 'ovelha', 'lesma',) vogais =…
-
3
votes1
answer46
viewsHow to print/insert in an organized way inside a csv file a tuple in Python
Would anyone know how to print a tuple as follows: amount_of_commits,author 148, Steve Ellis 2, Alex Kwiatkowski 2, Thomas 1, Dan Forbes 1, David Parker 1, John Barker 1, Thomas Hodges…
-
2
votes1
answer3340
viewsPython: Unsupported error operand type(s) for /: tuple and 'int'
Hi, I’m having a problem with a Python function, which involves a tuple stack. When performing this assembly function calling the tuple tuple votes: votacoes = ( (0, 15729, 220408, 1297, 0, 3040,…
-
2
votes2
answers212
viewsAssign Tuple return in two variables
Has a method that returns a tuple with two strings. The return I want to record in two different variables, only I’m having to call the method twice to pick one item at a time. string retorno1 =…
-
2
votes1
answer1043
viewsRead Data from a. csv file and pass line values to Tuple
The data in the.csv cities file is organized as follows: Lisbon,Madrid,600 Madrid, Paris,650 import csv with open('cidades.csv', 'r') as f: # Somente r para leitura do arquivo list1 =…
-
2
votes1
answer397
viewsSize of tuple lists in a df
I have the following df n_words Words . 220 [('trabalho', 17), ('monitor', 17), ('via', 16... 3114 [('atend', 863), ('ortopedico', 863), ('proced... 5 [('anomalos', 2), ('feixes', 1),…
-
1
votes1
answer2796
viewsTransfer of python files, client-server
Guys I have a problem in my code, I need to develop an application that is able to send a file to a server and also be able to recover files from the server I’m using a tuple to send the data to the…
-
1
votes1
answer245
viewsDatabase in Tupla
I need a code that receives data (values) and prints them according to your key. Each entry corresponds to a given of a hypothetical person, which contains Age, Name, Sex, Marital Status, Number of…
-
1
votes1
answer91
viewsDoubt def function with tuple mode input
Good person I have the following code: def tuplas(x): return x[::2] tuplas(('Hello', 'World', 'estamos', 'vivos')) This code will work perfectly, but if I remove the parentheses of my tuple,…
-
1
votes1
answer188
viewsComplex operations with Python (pygame.math.Vector2)
I am learning Python and I came across a complex expression that derives from pygame.Vector2: import pygame x = pygame.math.Vector2(1,2) b = x * 5 - (1, 2) print(x) print(b) Upshot: [1, 2] [4, 8] In…
-
1
votes1
answer1266
viewsHow to add elements to the tuple using a function?
def funcao(): int(input('insira um número:')) tupla = (funcao(), funcao(), funcao(), funcao()) print(tupla.count(9)) print(tupla) insira…
-
1
votes1
answer220
viewsAdd tuple in Python set
I am creating a graph with the following rules: The graph is a dictionary. The vertices are the keys of this dictionary and the values are the edges. Since I can have more than one edge for a…
-
1
votes3
answers84
viewsFind largest element index in the list
I am putting together a code that creates a list with 3 items of purchase, and within this list some tuples with the names of the products and the respective prices. I want to find the lowest price…
-
1
votes1
answer298
viewsHow to return a tuple to a function in Haskell?
I started messing with Haskell because of some college activity, and I’m having doubts about what the error in my code might be. The program will have two functions. 'tam', which will return the…
-
0
votes1
answer230
viewsDifference between tuple and set
I’m working with python and I was wondering what would be the difference between a set(set()) and a tuple(tuple()). I know that both are delimited with '()'. But I tried to assign a set attribute to…
-
0
votes1
answer1178
views -
0
votes1
answer1178
views -
0
votes1
answer130
viewsIndex of tuples in a list - python
Organisation of information in the file (City, City, Distance) import csv with open('cidades.csv', 'r') as f: list1 = [tuple(line.values()) for line in csv.DictReader(f)] for i in list1:…
-
0
votes0
answers210
viewsHow to access Tupla elements?
How to access the elements of this tuple: StringElement('24929426', attributes={'IdType': 'pubmed'}) I want to extract the attributes: '24929426' 'IdType': 'pubmed' The excerpt of the code that…
-
0
votes1
answer213
viewsHow to make the elements of a tuple to be the arguments of a python function?
I will first remove the problem and then explain what I am trying to do. If you know how to answer the short problem, you don’t need to see the rest. Is there a way to pass the elements of a tuple…
-
0
votes1
answer152
viewsPython - Type function in tuples
Hello, I’m trying to make a program in Python, which gets a positive integer number. That program shall verify that it is whole (with the type function) and if it is positive. Should return a…
-
0
votes1
answer148
viewsTuples: index out of range - recursion
I have a problem with index out of range in my tuple. The purpose of the code is to create a recursive function that finds a substring inside a tuple with elements of any kind. Someone could help me…
-
0
votes0
answers972
viewsDeep search - python
import csv with open('cidades.csv', 'r') as f: list2 = [tuple(line.values()) for line in csv.DictReader(f)] def dfs_helper(list2, start_city, end_city): pilha = [] visited = [] adj_cities =…
-
0
votes1
answer131
viewsHow to create tuple with key receiving value?
I would like to create a method that returns the Django ORM FILTER parameters. I will have to use these filters at various times, I would like to create this generic method. Follow the example: def…
-
0
votes1
answer55
viewsHow to test if all elements are 2-element tuples
I am solving an exercise that I first have to test whether the argument received is a Double. If yes, I have to test if all its elements are tuples of 2 elements, where the first is a string, and…
-
0
votes1
answer792
viewsHow to remove a dropdown from within a list
Good Afternoon, I have a problem with a job that is: I have a function that needs lists to organize various elements according to predefined characteristics. My question is how to remove a dropdown…
-
0
votes3
answers347
viewsReturn the oldest person from a list with tuples
The question is this: ; Consider that a person has the format Tuplo - (name, year of birth, city). Create a senior function that receives a list of people and returns the oldest person in the group.…
-
0
votes1
answer897
viewsCreate tuples with random values
Is it possible to create a tuple with random size and values? If so, how? ex: Run -->(0, 4 , 5) Run --> (2, 1, 7, 9) Run --> (7)... If it was a list I’d use the code: from random import…
-
0
votes1
answer73
viewsremove duplicates by prespetiva of tuples
I have this code working, yet I wanted to do it from the perspective of the tuples. Can assist? def remove_repetidos(lst): lista = [] #lista vazia for i in lst: if i not in lista: lista.append(i)…
-
0
votes1
answer266
viewsTable in Python
Good night, I need to make a Python function that receives a list of tuples with real dollar and real dollar dollar quotations return a string that, when printed, generates a table of quotations. I…
-
0
votes0
answers41
viewsHow to create a single file that stores the details of the generated information (order)?
have_discount = [] no_discount = [] for each_price in purchases_prices: b = bool_gen(p) if b: have_discount.append(apply_discount(each_price,b)) have_discount = [round(each_price, 2) for each_price…
-
0
votes0
answers46
viewsSearch for elements in tuples within a list
I made this code to search for an event, initially, I was unable to make the method print_events work, now it works, needs adjustments and improvements still and make work the formatting methods, if…
-
-1
votes1
answer71
viewsMysql Update on Average Students
Hi, good, I have a comic book with several students inserted, and in the exercise I need to average them and insert them in a new column. But when I do a test select before I update my command it…
-
-1
votes2
answers586
viewsHow to count repeated elements in a list of tuples?
listaAnimais=[('leao', 'Simba'), ('javali', 'Pumba'), ('leao', 'Scar'), ('hiena', 'Banzai'), ('leao', 'Mufasa')] #especie,nome dicEspecies={} for especies,nome in listaAnimais:…
-
-1
votes2
answers69
viewsIterations in a tuple list
Good afternoon, I have the following problem: I have a list of tuples called list_chromosomes, with 10 positions. I want to open a new position at the end of it (11th position), where it will…
-
-2
votes1
answer128
viewsQuery data in a txt file with python Tkinter
I’m creating a simple system to query employee data stored in a file txt. def read_from_file(): with open('dados.txt') as file: for line in file: line = line.rstrip('\n') nome, matricula,…