i read a CSV file with few columns and created a class for those columns:
class member:
name = ""
vdate = []
data = []
for column in columns:
m = member()
m.name = column[1] + " " + column[2]
m.date = int(column[5]
Now, i'm trying to skip lines that have been read once from m.name, the skiped lines wont be append to
data = []
However, after I skiped those lines, I want the date value in the skip lines to be append to the vdate [] in the class.
I tried:
if m.name != m.name:
data.append(m)
else:
continue and vdate.append(m)
did not worked.
I do not think that a Class is the best way to go about this.
I would just have a simple dict to hold the name as a key and the date as a value. And then just check if each new line is in the dict. If it is not add it to the dict, and if it is just the date to a another list.
So that should give you a dict with key value pairs of names and dates, and a list with the dates where the name is already in the dict.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.