(Jan-11-2019, 01:54 PM)buran Wrote: pay attention to comments in the code (and ignore the typing errors :-))
Quote:# read header and all data in two variables -> header and data
# Note the asteriks in frot of data
# This way data will hold everything except the first element in ws.values
and if you are interested to read further
PEP 3132 -- Extended Iterable Unpacking
I did read that. But even though you told me that, I didn't understand how it worked. How it 'knew' that header was the first row. I didn't know that having multiple variables corresponded to rows, one at a time. I didn't know that the * picked up from not just row 2, but from whatever number the last variable was. You pointed me in the right direction with your comments, and that helped me to learn more.
I promise to do my best to read whatever you have taken the time to write! :)
groups = defaultdict(list) for row in data: group = row[-1][-1] groups[group].append(row)I was wondering if the word 'row' had any significance other than being easy to understand. I replaced it temporarily with the word 'this', and everything still worked fine.
Do I understand then, that since you used (list) for defaultdict, that it created a list and so when you say 'for xxxx in yyy', python just grabs the largest unit size, in this case being an entire row? I really am new to this stuff, and this might be basic, but I'm trying to make sure that I don't assume something and then later be confused when something doesn't work the way I thought it did.
Joe