All Questions
Tagged with namedtuple list
37
questions
0
votes
1
answer
129
views
Print named tuple value in a list
A function is returning me the below list of named tuples:
[popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768), popenfile(path='/var/log/monit.log', fd=4, position=...
0
votes
2
answers
54
views
Search substring in list of dictionaries of namedtuples keyed with an event type
I have created a list of dictionaries of named tuples, keyed with an event type.
[{'EVENT_DELETE': DeleteRequestDetails(rid=53421, user='user1', type='EVENT_DELETE', reviewed=1, approved=1, completed=...
-1
votes
1
answer
343
views
Python random.choices index with named tuples
So I want to know the position of the randomly named_tuples sampled by the random.choices.
I sample it with a list of the same length and positions (memory, probabilities)
sample_indices = random....
0
votes
1
answer
39
views
Replace a element in namedtupled of a nested list
I would like to edit the vote, but I cannot find how to do it. Please help
this_list = [Mascot(mascot_name='Peter', species='Anteater', school_name='UC Irvine', number_of_votes=137988),
Mascot(...
0
votes
1
answer
966
views
Retrieve all named element from namedtuples in a subset of a list in Python
I have a list of namedtuples. I would like to generate a list of a specific named element of a subset of the namedtuples in the list, based on a list of indices to select.
Example would be:
from ...
0
votes
1
answer
243
views
What is the fastest way to find the average for a list of tuples in Python, each tuple containing a pair of namedtuples?
import numpy as numpy
from collections import namedtuple
from random import random
Smoker = namedtuple("Smoker", ["Female","Male"])
Nonsmoker = namedtuple("...
1
vote
1
answer
166
views
Regex from a list of strings in Python
I have a list named as Statement created from pdf using pytesseract and Regex:
Statement= ['07-10-2019 UPI/927912685773/UPI/surya.balaji94@/Citibank 6,677.00 2,36,804.08',
'07-10-2019 MOBILE ...
-1
votes
4
answers
48
views
How to display a list of tuples and count the same number of elements
input
def inisial(daftar):
daftar = (
"Michael","Viny","Aurelio","Michael",
"Felix","Kevin","Vincen","Vincen","Michael")
inisial(daftar)
output:
Michael
Viny
Aurelio
Michael2
Felix
...
-1
votes
1
answer
308
views
How to check if NamedTuple is in list?
I tried to check if an inctance of a NamedTuple "Transition" is equal to any object in the list "self.memory".
Here is the code I tried to run:
from typing import NamedTuple
import random
import ...
4
votes
2
answers
1k
views
Flatten list of nested namedtuples to list of dictionaries
Sample:
import collections
A = collections.namedtuple('A', 'a b c')
B = collections.namedtuple('B', 'x y z w')
L = [A(a='CODE1', b=B(x=2, y='u', z='v', w='a'), c=10),
A(a='CODE2', b=B(x=4, y=...
0
votes
1
answer
33
views
How do you index a list of namedtuples containing stock info given a range of date?
[Stock(date='2019-11-20', open='150.3100', high='150.8400', low='148.9600', close='148.9700', volume='11291822', indicator=0, signal='', change=0), Stock(date='2019-11-19', open='150.8800', high='151....
1
vote
1
answer
600
views
Use partial attributes from namedtuple for comparison
I have a namedtuple with fields (x, y, z) where z is optional.
Comparison operators like 'in' considers all fields for comparison
from collections import namedtuple
p = namedtuple('p' , ('x' ,'y', '...
-2
votes
2
answers
396
views
How to loop until all lines read from a file?
I'm trying to set up a score system where I need to input all the scores from a text file into an 'array of records'.
I'm fairly new to Python and hope for a simple solution.
In my program, the ...
0
votes
2
answers
197
views
Python: specific value in a named tuple of a list of tuples
I was wondering if it is possible to print a value that is inside a list of lists of tuples if you already know the indexes path.
1. List[i][j]
2. list2[x][y]
3. list3[z][w]
4. etc.
I ...
0
votes
1
answer
48
views
Neater way to write huge lists for creating named tuples with default values
I have a named tuple object defined with 63 different items in it. I use the _make function. I think this approach will work but need 4x63 more rows for the try except statements. There has to be a ...