Skip to content

Instantly share code, notes, and snippets.

@oC-n
Created June 28, 2021 14:47
Show Gist options
  • Save oC-n/0daf28e4372bde55c1e96f630f237283 to your computer and use it in GitHub Desktop.
Save oC-n/0daf28e4372bde55c1e96f630f237283 to your computer and use it in GitHub Desktop.
Python for Data Science, AI & Development - Week 4 Hands-On Lab: Writing Files with Open
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oC-n
Copy link
Author

oC-n commented Jun 28, 2021

Notes:

  • members = memList.readlines() will read all (remaining) lines in file.
  • inactive.write(members.pop(members.index(member))) would remove the current member from the list, members, and append it to the file, inactive, but this will only work if we are manually indexing through members, i.e. not using e.g. "for member in members".
  • If we expect fewer members to fall into "inactive" category than "active", more efficient to collect inactive members.
  • In that case, the final write loop decides where to write by checking whether the member is in the "inactive" collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment