Questions tagged [namedtuple]

namedtuple is a data structure provided by the Python collections module. It enables the creation of tuples with named elements (e.g., a Student tuple with the values (name, school, age) rather than a tuple with just two strings and an integer).

namedtuple is a data structure provided by the Python collections module. It enables the creation of tuples with named elements (e.g., a Student tuple with the values (name, school, age) rather than a tuple with just two strings and an integer).

Documentation: collections module in Python 3.

Recently, a declarative API for namedtuples is also provided by the typing module.

545 questions
-2
votes
2 answers

why doesn't this code work in python 3.4?

Define a function called restaurant_price that takes one argument, a Restaurant, and returns the value of the price field of that Restaurant. So define a list containing a few Restaurants I keep getting the error of Restaurant not defined. This is…
anonymous fox
  • 39
  • 1
  • 5
-3
votes
2 answers

Python parameter behavior

My understanding of function parameters in Python is that they are like empty objects until function call and that's it. eg. def square(x): #where x is an empty var defined here. return x*x #for the scope of this function So how does this work,…
user9166255
-3
votes
1 answer

exec class_definition in namespace in python

this Code snippet is namedtuple function of collections module in python.when I see it ,I don't understand it. class_definition is formated string, namespace is dict, exec could code ogject or string and so on, exec class_definition in namespace how…
-4
votes
1 answer

How to convert class objects to named tuples?

I really want to use namedtuples instead of class objects class objects class ZoneFileObject(object): def __init__( self, descriptor='', name='', filehandle='', ): self.descriptor =…
Prabhu S
  • 15
  • 6
-4
votes
1 answer

Averaging a list of tuples

PLEASE HELP ME! I'M SUPER NEW AT THIS AND THINK I'VE GONE COMPLETELY OFF SOMEWHERE. I Was given a csv file to use and extrapolate data from. Had a pretty extensive list of countries with their corresponding GDPs, unemployment rates and more. I'm…
Solo
  • 1
  • 1
1 2 3
36
37