Python Forum
what function should i use to tidy up my code (extreme beginner)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what function should i use to tidy up my code (extreme beginner)
#4
the keys of the dicts will be the player names or their nicknames,e .g. am (depending how you expect your user to provide the search term).
the values will be instances of class Player, e.g. with just first three players
class Player:
    def __init__(self, full_name, goals, shots, headers, tackles, passes, clean_sheets):
        self.nm = full_name
        self.gl = goals
        self.st = shots
        self.hd = headers
        self.tk = tackles
        self.ps = passes
        self.cs = clean_sheets
 
 
players = {'am':Player('Alfredo Morelos', 35, 10, 5, 5, 6, 10),
		   'rk':Player('Ryan Kent', 20, 10, 7, 5, 6, 8),
		   'jd':Player('Jermaine Defoe', 30, 6, 5, 5, 6, 8)}
then you can access them as with normal dict, using the key
You should know that everything in python is object. it doesn't matter if it is some built-in type or custom class - it can be value in a dict

If you don't plan to expand the class, built-in namedtuple from collections module would do just the same job.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: what function should i use to tidy up my code (extreme beginner) - by buran - Dec-16-2019, 03:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner: Code not work when longer list raiviscoding 2 977 May-19-2023, 11:19 AM
Last Post: deanhystad
  Putting code into a function breaks its functionality, though the code is identical! PCesarano 1 2,116 Apr-05-2021, 05:40 PM
Last Post: deanhystad
  Code not reading http link from .txt file (Beginner level) plarrip 3 2,558 Dec-17-2020, 11:33 PM
Last Post: bowlofred
  Beginner: I need help understanding few lines of a code. hop_090 1 1,782 Sep-07-2020, 04:02 PM
Last Post: Larz60+
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,964 Jun-18-2020, 04:59 PM
Last Post: QTPi
  A beginner code... TheDude 7 3,462 Jun-18-2020, 05:39 AM
Last Post: TheDude
  [Beginner] Code is not producing desired result fakej171 2 2,564 Mar-21-2020, 10:26 AM
Last Post: buran
  Beginner at Python. Trying to count certain integer from random string of code kiaspelleditwrong 3 2,556 Oct-14-2019, 10:40 AM
Last Post: perfringo
  Beginner trying to code in python RA0211 1 1,921 Sep-26-2019, 11:10 AM
Last Post: emryscass
  Beginner problem, replace function with for loop Motley_Cow 9 4,915 Sep-13-2019, 06:24 AM
Last Post: Motley_Cow

Forum Jump:

User Panel Messages

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