Just studying data structures in python for a project and can’t work out the difference in a dictionary and a data structures in this form:
class Address:
def __init__(self, house_number, house_street, house_city,
house_county, house_postcode):
self.number = house_number
self.street = house_street
self.city = house_city
self.county = house_county
self.postcode = house_postcode
def __repr__(self):
return ('<Class: \'Address\', '+ str(self.number) + ' ' +
self.street + ' ' + self.city + ' ' +
self.county + ' ' + self.postcode + '>')
## Creates an object Address and assign it to a variable
my_address = Address(1, 'abc', 'def', 'ghi', 'jkl')
## Print the object My_address
print 'Address object:', my_address
print 'house number:', my_address.number
## change house number
my_address.number = 555
print 'NEW house number:', my_address.number
The code sample is modified from sample code given in a lecture at university of york.
A python
dictis a highly optimized hash table, which is a data structure.So, to put it differently, a python
dictis one example of a data structure. So are theset,list,stringandunicodetypes. A custom class is again another data structure, one that is highly customizable to your application needs.From the WikiPedia entry on Data structure: