Maintenance Mode

Have Patience Working on it

SET ADT Using Students courses example

Example of SET ADT in python 
Two students are taking different course . How a set data structure will help to apply some operations to obtain information.


# set of two students courses names
# student 1
smith = set()
smith.add( "CSCI-112" )
smith.add( "MATH-121" )
smith.add( "HIS-340" )
smith.add( "ECON-101" )
# stuendt 2
roberts = set()
roberts.add( "POL-101" )
roberts.add( "ANTH-230" )
roberts.add( "CSCI-112" )
roberts.add( "ECON-101" )
# students have taken exact same or not
# if not then find same course
if smith == roberts:
print("Smith and Roberts are taking the same courses. ")
else:
sameCourses = smith.intersection(roberts)
# print(sameCourses)
if len(sameCourses) == 0:
print("Smith and Roberts are not taking any of the same courses. ")
else:
print("Smith and Roberts are taking some of the same courses. ")
# printing same courses
for course in sameCourses:
print(course)
# Courses only smith is taking not roberts
print("Courses only smith is taking not roberts")
uniqueCourses = smith.difference(roberts)
for course in uniqueCourses:
print(course)
view raw setADT.py hosted with ❤ by GitHub
SET ADT Using Students courses example SET ADT Using Students courses example Reviewed by Leaf Code on September 15, 2020 Rating: 5

No comments:

SET ADT Using Students courses example

Powered by Blogger.