This is my first question on StackOverflow, and I searched so many sites, but could not find what I was looking for (or did not notice). Please do not bother me :)
Also, this is my first programming experience with Fitton, and I'm confused.
I have a TXT file and it has 3 columns inside separated by WhiteSpaces. These columns are DeptID , CourseID , CourseID .
Here is an example of data:
101 10001 23 102 10002 30 102 10004 5 102 10005 13 105 10006 59 105 10007 77
So, whenever I call the indexes DeptID and CourseID , the program gives me the number of students studying.
Example: NumberofEnrolled("101","10001") should give the answer 23 .
Should matrices be used instead? Because I have lost. I know what I want, but I do not know what it is called in Fiton.
import numpy depts = [] courses = [] file = open("C:\\Info.txt", "r") # SPLIT EVERY LINE INTO 3 PIECES : DeptID , CourseID , Enrolled for line in file: depts.append(line.split()[0]) # ADD Depts courses.append(line.split()[1]) # ADD Courses # CLOSE THE FILE file.close() # I HAVE TRIED NUMPY BUT COULDN'T HANDLE WITH IT. numpyList = numpy.zeros((57, 57), dtype = numpy.int32) dept_array = numpy.array(dept) course_array = numpy.array(course) test_dict = {} for i in range(len(dept_array)): test_dict[dept_array[i]] = course_array[i]
Result
test_dict:
{'101': '10001', '102': '10005', '105': '10007'}
This output only accepts the latest data for multiple data. I think I need a type that can contain several pairs inside.