Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what data structure to use?
#3
If it were me I'd use a class.

class Zip_Code_Entry :
	def __init__ (self, zip_code) :
		self.zip_code = zip_code
		self.amenities = {}

	def add_amenity (self, amenity: str) :
		if amenity in self.amenities :
			self.amenities [amenity] += 1
		else :
			self.amenities [amenity] = 1

	def show_amenities (self) :
		for key, value in self.amenities.items () :
			print (f'There are {value} {key} in {self.zip_code}.')

first_one = Zip_Code_Entry ('12345')
first_one.add_amenity ('Churches')
first_one.show_amenities ()
Reply


Messages In This Thread
what data structure to use? - by Winfried - Mar-15-2021, 10:44 PM
RE: what data structure to use? - by deanhystad - Mar-15-2021, 11:30 PM
RE: what data structure to use? - by BashBedlam - Mar-16-2021, 12:14 AM
RE: what data structure to use? - by Winfried - Mar-16-2021, 11:18 AM
RE: what data structure to use? - by buran - Mar-16-2021, 12:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I add certain elements in this 2d data structure and calculate a mean TheOddCircle 3 1,607 May-27-2022, 09:09 AM
Last Post: paul18fr
  Appropriate data-structure / design for business-day relations (week/month-wise) sx999 2 2,863 Apr-23-2021, 08:09 AM
Last Post: sx999
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,935 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  How to use Bunch data structure moish 2 2,981 Dec-24-2020, 06:25 PM
Last Post: deanhystad
  Correct data structure for this problem Wigi 13 4,746 Oct-09-2020, 11:09 AM
Last Post: buran
  difficulties to chage json data structure using json module in python Sibdar 1 2,121 Apr-03-2020, 06:47 PM
Last Post: micseydel
  File system representation in a data structure Alfalfa 1 2,113 Dec-18-2019, 01:56 AM
Last Post: Alfalfa
  Custom data structure icm63 2 2,583 Mar-27-2019, 02:40 AM
Last Post: icm63
  Nested Data structure question arjunfen 7 4,329 Feb-22-2019, 02:18 PM
Last Post: snippsat
  Display 20 records at a time,data structure or loop pythonds 1 2,506 Mar-29-2018, 11:09 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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