paid_students=[]
for students in enrollments:
if students['days_to_cancel']==None or students['days_to_cancel']>7:
paid_students.append(students)
print len(paid_students)
Output:
1640
The value of len(enrollments)
is also 1640
. Why are all the rows getting appended to the paid_students
list
even though many rows in the enrollments have ['days_to_cancel']
values having wide ranges.
Example data for enrollments
{u'account_key': u'448',
u'cancel_date': u'2014-11-10',
u'days_to_cancel': u'5',
u'is_canceled': u'True',
u'is_udacity': u'True',
u'join_date': u'2014-11-05',
u'status': u'canceled'}
{u'account_key': u'448',
u'cancel_date': u'2015-01-27',
u'days_to_cancel': u'0',
u'is_canceled': u'True',
u'is_udacity': u'True',
u'join_date': u'2015-01-27',
u'status': u'canceled'}
Source-Udacity