tuples

split by comma and ignore if comma in quotes a data from List of Tuples – Python

split by comma and ignore if comma in quotes a data from List of Tuples – Python Question: I have a list of tuples. lt = [(‘051623’, ‘O143’, ‘1.23’, ‘2023-05-16T18:30:00’, ‘1M allen’, ‘millan’), (‘051623’, ‘O207’, ‘1.23’, ‘2023-05-16T18:35:00’, ‘nM Mn, 4nM, 35uM Fe’, ‘wilo’)] Need to convert to csv string by comma separated but while split …

Total answers: 4

Expand list of tuples

Expand list of tuples Question: I have a big list of tuples (20-30 million entries). Each sub-tuple has three pieces of information (start, end, value) and is supposed to only represent one position in a sequence. However, the program generating this data has concatenated some of the values of adjacent positions if the value is …

Total answers: 2

Transform a dictionary into a list of tuples with Python

Transform a dictionary into a list of tuples with Python Question: I want to transform a dictionary into a list of tuples, but doing it ‘row-wise’: the first tuple should cointain the first values, the second tuple the second values, and so on. I have some working code, but I wonder if there is a …

Total answers: 2

Tuple unpacking and np.max() giving unexpected values

Tuple unpacking and np.max() giving unexpected values Question: I have a dataset that I am trying to filter and apply an adjustment value using tuples. df = pd.DataFrame({ ‘loannum’: [‘1’, ‘2’, ‘3’, ‘4’], ‘or_dep’: [250000, 650000, 1000000, 300000] }) loan2adj = [(‘1’, 50000), (‘3’, 250000), (‘2’, 100000)] My expected output looks like this. loannum or_dep …

Total answers: 1

In Python how to convert a string with special characters to a tuple

In Python how to convert a string with special characters to a tuple Question: would really appreciate any help on this one! I have a string: "<Cell ‘test’.B45>" I need to convert this to a tuple with only one object in it, so that looks like this: ((<Cell ‘test’.B45>)) So to do this I have …

Total answers: 1

How can I clear a list of segments from nested segments (Python)

How can I clear a list of segments from nested segments (Python) Question: My respect, colleagues. I have a list of segments which may include nested segments that should be deleted. For example we have a list (or maybe other data structure) of tuples: [(50, 60), (10, 20), (10, 40), (40, 60), (60, 80), (75, …

Total answers: 1

Generate all combinations of positive and negative

Generate all combinations of positive and negative Question: I have this list of tuples a = [(1, 2), (2, 1)] And need all of the possible combinations of negative and positive: b = [(1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1)] I’ve tried using itertools.product(): xs = …

Total answers: 5

Make set keep order of a tuple

Make set keep order of a tuple Question: In the code below, how can I use keep using set to have unique values, but also make set keep the order of how the filters are typed in? >>> filters = (‘f1’, ‘f2’) >>> set((*filters, ‘f3’)) {‘f1’, ‘f3’, ‘f2’} # expected: {‘f1’, ‘f2’, ‘f3’} Asked By: …

Total answers: 2

How to store a tuple of floats into a file, open and read it to extract the mean per column?

How to store a tuple of floats into a file, open and read it to extract the mean per column? Question: I am computing the following scores iteratively which generates a new set of the following scores in each iteration: add_score, keep_score, del_score = get_corpus_sari_operation_scores(sources, prediction, references) I first want to store them into a …

Total answers: 2