Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>#!/usr/bin/env python import sys ##Initials,Last,First,ShiftStart,ShiftEnd s='''BAB,Smith,Bob,10:00a,1:00p JCJ,Jones,Jill,11:00a,3:00p JIH,Hernandez,Jose,1:00p,4:00p BAB,Smith,Bob,1:00p,3:00p JIH,Hernandez,Jose,5:00p,9:00p JCJ,Jones,Jill,3:00p,3:30p JCJ,Jones,Jill,3:30p,5:00p DJM,Martin,Dominique,8:00a,11:00a''' db = {} for line in s.split('\n'): Initials,Last,First,ShiftStart,ShiftEnd = line.split(',') if Initials in db: db[Initials][2].append((ShiftStart,ShiftEnd)) else: db[Initials] = (Last,First,[(ShiftStart,ShiftEnd)]) for Initials,v in db.iteritems(): Last,First,shifts = v sys.stdout.write(Initials + ',') sys.stdout.write(Last + ',' + First) for shift in shifts: ShiftStart,ShiftEnd = shift sys.stdout.write(',' + ShiftStart + ',' + ShiftEnd) sys.stdout.write('\n') </code></pre> <p>Alternatively, you could do a very object-oriented program:</p> <pre><code>import sys ##Initials,Last,First,ShiftStart,ShiftEnd s='''BAB,Smith,Bob,10:00a,1:00p JCJ,Jones,Jill,11:00a,3:00p JIH,Hernandez,Jose,1:00p,4:00p BAB,Smith,Bob,1:00p,3:00p JIH,Hernandez,Jose,5:00p,9:00p JCJ,Jones,Jill,3:00p,3:30p JCJ,Jones,Jill,3:30p,5:00p DJM,Martin,Dominique,8:00a,11:00a''' class Shift(object): def __init__(self,ShiftStart,ShiftEnd): self.ShiftStart,self.ShiftEnd = ShiftStart,ShiftEnd def __str__(self): return '%s,%s' % (ShiftStart,ShiftEnd) class Person(object): def __eq__(self, p): if self.Initials != p.Initials: return False if p.Last is not None and self.Last != p.Last: return False if p.First is not None and self.First != p.First: return False return True def __init__(self,Initials,Last,First): self.Initials,self.Last,self.First = Initials,Last,First self.Shifts = [] def __str__(self): return '%s,%s,%s' % (self.Initials,self.Last,self.First) def AddShift(people, person, shift): try: person = people[people.index(person)] except ValueError: people.append(person) person.Shifts.append(shift) people = [] for line in s.split('\n'): Initials,Last,First,ShiftStart,ShiftEnd = line.split(',') AddShift(people, Person(Initials,Last,First), Shift(ShiftStart,ShiftEnd)) for person in people: print '%s,%s' %(person, ','.join(map(str,person.Shifts))) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload