tuples

Extract tuple elements in list

Extract tuple elements in list Question: my_tuples = [(1, 2, 3), (‘a’, ‘b’, ‘c’, ‘d’, ‘e’), (True, False), ‘qwerty’] For this tuple, how can I append all values in list and dictionary. For example, I want output like list1 = [1,2,3,a,b,c] so on and for dictionary I want output like{1:1,2:2,3:3,4:a}. Thanks in advance. For list, …

Total answers: 1

Why am I getting an error when I am trying to change a tuple

Why am I getting an error when I am trying to change a tuple Question: I am trying to change a tuple but, it keeps giving me this error: Traceback (most recent call last): File "main.py", line 2, in <module> my_tuple[1] = ‘y’ TypeError: ‘tuple’ object does not support item assignment My code is: my_tuple …

Total answers: 6

create tuple from ranges in python

create tuple from ranges in python Question: Is there a way in python to create a tuple of months and years (as: [(2020, 1),(2020,2)…] ) by using the tuple() function? My code: monthyears = [] for y in range(2020,2017,-1): if y == 2018: m_end = 6 else: m_end = 0 for m in range(12,m_end,-1): monthyears.append((y,m)) …

Total answers: 3

substracting list of tuples from another list of tuples in python

substracting list of tuples from another list of tuples in python Question: I have two lists of tuples but imagine long lists of tuples and the idea is to get these two conditions tuples that are only in list2 get rid off of individul tuples where the first element of tuples in list1 match the …

Total answers: 2

List of tuples to DataFrame w. column for elements, column for tuple length

List of tuples to DataFrame w. column for elements, column for tuple length Question: I have a list of tuples of different lenghts, where the tuples can be thought to encode teams of people, such as: data = [(‘Alice’,), (‘Bob’, ‘Betty’), (‘Charlie’, ‘Cindy’, ‘Cramer’)] From this, I would like to create a DataFrame with a …

Total answers: 3

How to fetch data in Python from SQL as a list of strings instead of tuples?

How to fetch data in Python from SQL as a list of strings instead of tuples? Question: I’m trying to get the columns names of an SQLite table, but I’m getting back a list of tuples with the names. cur.execute(”’SELECT name FROM PRAGMA_TABLE_INFO(‘Emails’)”’) .fetchall()) If I print this the output is: [(’email’,), (‘count’,)] How can …

Total answers: 1

get rid of repeated self values and keep only one out of (2,0) (0,2)?

get rid of repeated self values and keep only one out of (2,0) (0,2)? Question: according to @KellyBundy answer, I’d like to get rid of repeated self-values (2, 2), (0, 0) and keep only either (2, 1) or (1, 2), keep only either (1, 0) or (0, 1) and get rid of repeated (0, 2) …

Total answers: 1