Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 93 results for
named-tuple
- Page 1
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by BearofNH
… data string (potential csv file with ; separator) to create a
named
tuple
of US states tested with Python27 and Python33 by vegaseat… in data_str.split('\n') if line) #pprint.pprint(data_list) # test #
named
tuple
States behaves like a class, and has much less overhead…
Helped with type declaration in named tuple
Programming
Software Development
12 Years Ago
by hughesadam_87
…, but to no avail. Is there anyway to make the
named
tuple
aware of what data type each field ought to have…
US states named tuple (Python)
Programming
Software Development
11 Years Ago
by vegaseat
Just a little fun with Python's
named
tuple
, behaves like a class but is much leaner.
Exploring Named Tuples (Python)
Programming
Software Development
14 Years Ago
by vegaseat
Starting with version 2.6 Python has introduced a new container called the
named
tuple
. You can use it similar to a class based record structure, but it has the memory efficiency of a
tuple
.
Re: Helped with type declaration in named tuple
Programming
Software Development
12 Years Ago
by hughesadam_87
This can be deleted, sorry for the haste.
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by vegaseat
Now here is a brain teaser, list all the states that joined the Union after 1865.
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by BearofNH
> Now here is a brain teaser, list all the states that joined the Union after 1865 Add the following to the end: print('-'*35) print("US states admitted after 1865:") for state in instance_list: if int(state.date[-4:]) > 1865: print("{:15} {}".format(state.state, state.date[-4:]))…
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by BearofNH
Oops, the output is: ----------------------------------- US states admitted after 1865: Alaska 1959 Arizona 1912 Colorado 1876 Hawaii 1959 Idaho 1890 Montana 1889 Nebraska 1867 New Mexico 1912 …
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by vegaseat
Another brain teaser. Can you turn this snippet into a Quiz with multiple choices?
Re: US states named tuple (Python)
Programming
Software Development
11 Years Ago
by vegaseat
Wow BearofNH, great coding and fun to play.
Re: named colors in wxpython
Programming
Software Development
10 Years Ago
by ZZucker
… in wxPython's wx.lib.colourdb the database has 630
named
colors use wx.lib.scrolledpanel.ScrolledPanel and wx.GridSizer to… = ('SNOW', 255, 250, 250) hexstr = "#%02X%02X%02X" %
tuple
(line[1:]) s = "%3d %s" % (n, line[0…
Records in python- small wrapper around namedtuple
Programming
Software Development
12 Years Ago
by hughesadam_87
…is an immutable array container just like a normal
tuple
, except namedtuples have field designations. Therefore, elements can…=['a', 'list', 'has been entered']) Because a
named
tuple
is a very basic container, it really doesn't care… demonstrate by example- let's create a Person
named
tuple
with the new class. We will define our stringent…
Re: Custom named tuples for record storage
Programming
Software Development
12 Years Ago
by hughesadam_87
… passes in an interable. @classmethod def _make(cls, iterable, new=
tuple
.__new__, len=len): 'Make a new %(typename)s object from… sense since the record class is mutable, so I replaced
tuple
.__new__ with object.__new___ But I get an attribute error…
Re: compare values in a tuple/list
Programming
Software Development
17 Years Ago
by katharnakh
… what you have said earlier, cell(line). BTW, where is
tuple
/list comparission? [Code=Python] >>> import cells Traceback…>", line 1, in ? import cells ImportError: No module
named
cells >>> [/Code] ??
Re: compare values in a tuple/list
Programming
Software Development
17 Years Ago
by flaerpen
…>", line 1, in ? import cells ImportError: No module
named
cells >>> [/Code][/QUOTE] 'cells' is a module…
Re: Custom named tuples for record storage
Programming
Software Development
12 Years Ago
by TrustyTony
Also the test I mentioned is changed in namedtuple in collections: if not all(c.isalnum() or c=='_' for c in name): This is basically same as I suggested. I think you should not call your class tupple as it is mutable and does not inherit from
tuple
.
Re: Why would you use tuples?
Programming
Software Development
11 Years Ago
by vegaseat
And then there is the
named
tuple
that uses
named
indexing rather than sequential numeric indexing. It is supposed to … = co.namedtuple('employee_record', 'name, department, salary') # load the
named
tuple
and create
named
instances bob = Record('Bob Zimmer', 'finance', 77123) tim = Record('Tim…
Re: Parsing a text file
Programming
Software Development
13 Years Ago
by TrustyTony
Named
tuple
is for convenience and allows the column to be variable. …
Re: Starting Python
Programming
Software Development
13 Years Ago
by vegaseat
…, Person): """ load the
named
tuple
with the data list and create a dictionary….namedtuple('movie_star', 'name, age, weight') # load the
named
tuple
and get a dictionary of instances nt_dict = create_nt_dict(data_list,…locals()) print('<>'*35) # work with the
named
tuple
... print("names of instances =\n%s"…
Re: Starting Python
Programming
Software Development
15 Years Ago
by bumsfeld
… Python3 import collections as co # set up
named
tuple
where staff is the identifier # and the …args #nt3 = ntup('Jack', 'Schiett') # show the
named
tuple
print(nt1) # staff(fname='Hank', sname='Zoller', age… ('sname', 'Bartok')]) Bartok """ # convert dictionary to
named
tuple
d = {'age': 34, 'sname': 'Bartok', 'fname': 'Bjorn'}…
Re: A taste of Swift part 1
Programming
Computer Science
9 Years Ago
by vegaseat
An example of a
named
tuple
, actually an array of
named
tuples. With a
named
tuple
you can use index numbers or more meaningful names ... // create…", "MI", 942000, 177000) ] // access
tuple
at array index 1 // item at
tuple
index 0 println(tdata[1].0) // FST…
Re: need advice on data structure and filtering
Programming
Software Development
14 Years Ago
by vegaseat
… be interested in. Here is an example ... [code]#
named
tuple
instances require no more memory than regular tuples # tested with…Wood') carl = default._replace(name='Carl Boor') # access by
named
index print(bob.name, bob.salary) # Bob Zimmer 77123 #…('name', 'department', 'salary') [/code]Note: Python 2.6 includes the
named
tuple
already.
Re: Reading two files?
Programming
Software Development
11 Years Ago
by vegaseat
…(';') for line in data_str.split('\n') if line] # create the
named
tuple
object Billing = namedtuple('bill', 'id, name, cat, quant, price') # create… some of Sneekula's code but simplified it with a
named
tuple
object instead of a class.
Re: simple list
Programming
Software Development
12 Years Ago
by Ene Uran
Look at this: #
named
tuples have
named
indexes they behave similar to class # instances but require no … # with Python module pickle import collections as co # create the
named
tuple
Movies = co.namedtuple('Movies', 'title, year, director, minutes, cast') record_list…
Re: Starting Python
Programming
Software Development
11 Years Ago
by vegaseat
… values ''' import time # take a slice of the current time
tuple
# values you want are in index 3, 4, 5 hr….localtime() #print(now) # test to get names (acts like a
named
tuple
) sf = "Current time values are {} hours {} minutes and {} seconds…
Re: Python nested objects, best practices.
Programming
Software Development
15 Years Ago
by slate
…/library/collections.html#namedtuple-factory-function-for-tuples-with-
named
-fields"]
named
tuple
[/URL], which is present in python 2.6 or…
Re: struct
Programming
Software Development
15 Years Ago
by scru
For
named
tuple
you need >= python26 (that includes python30). Note that if you intend to use it for calling into C code, namedtuple won't work.
Re: Create a Python Dictionary From a CSV File using CSV Module
Programming
Software Development
14 Years Ago
by jice
… csv with other dialect and use dict(zip()) instead of
named
tuple
. [CODE] """ datas.csv : "123"; "…
Re: Reading a csv file to a dictionary
Programming
Software Development
13 Years Ago
by TrustyTony
How about my
named
tuple
code in code snippets?
Re: Instance methods or general methods?
Programming
Software Development
12 Years Ago
by hughesadam_87
Thanks for the heads up. The
named
tuple
is a nice alternative. Would you say that the get_width() function that I presented above is non-pythonic then?
1
2
3
Next
Last
Search
Search
Forum Categories
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Forums
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2024 DaniWeb® LLC