I created the following class from which I can "create" students:
import itertools
class Student (object):
id_iter = itertools.count()
def __init__(self, studentName):
self.studentName = [studentName, next(self.id_iter)]
def __str__(self):
return str(self.studentName)
This way, each student gets a unique ID starting from 0. My example list:
stud1 = Student("Justa Student")
stud2 = Student("Another One")
stud3 = Student("One Morestudent")
I'd like to create a function which would return a similar looking list with both the student names and student IDs (I created this list with another, long code):
The output would return all students and their respective IDs. Later on, I'd like to have another function with removing students as well, I'm thinking of making the function with a for loop going until the highest ID, but I can't properly return stuff with the class.