Python Forum
Iterating over dictionaries with the namedtuple function (PyBite #108)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iterating over dictionaries with the namedtuple function (PyBite #108)
#3
My compliments DeaD_EyE, your answers are always very informative. But it is not what Drone asks.
(Jul-03-2020, 09:01 AM)Drone4four Wrote: My problem is how to reformat those operations into a function inside an actual script to automate that output. I’m completely lost trying to do that.

Drone4four, I do not understand your question. You can, also in Jupyter, fill in your code and save it? You must have learned how to define a function? The result should be something like:
from collections import namedtuple
 
BeltStats = namedtuple('BeltStats', 'score ninjas')
 
ninja_belts = {'yellow': BeltStats(50, 11),
               'orange': BeltStats(100, 7),
               'green': BeltStats(175, 1),
               'blue': BeltStats(250, 5)}

def add_stats(some_dict):
    test=0
    "add your code here
    "also study Dead_eye's advice
    return test

print(add_stats(ninja_belts))
Reply


Messages In This Thread
RE: Iterating over dictionaries with the namedtuple function (PyBite #108) - by ibreeden - Jul-03-2020, 11:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary lookups exercise (PyBite #109) Drone4four 14 5,967 Aug-10-2020, 06:41 PM
Last Post: Intr0spective
  Type conversion and exception handling (PyBite #110) Drone4four 5 35,414 Jul-27-2020, 11:33 AM
Last Post: DeaD_EyE
  "Slicing and dicing strings" - - PyBite #105 Drone4four 8 4,409 Jun-11-2020, 09:28 PM
Last Post: knackwurstbagel
  Help with homework problem - iterating a function midnitetots12 4 3,549 Feb-21-2018, 10:51 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020