1. def deduplicate_tokens(token_list):
  2. """
  3. Deduplicates a list of authentication tokens, preserving order.
  4. Args:
  5. token_list: A list of authentication tokens (strings).
  6. Returns:
  7. A new list containing only unique tokens from the input list,
  8. in the order they first appeared.
  9. """
  10. seen_tokens = set() # Use a set for efficient lookup
  11. deduplicated_list = []
  12. for token in token_list:
  13. if token not in seen_tokens:
  14. deduplicated_list.append(token)
  15. seen_tokens.add(token)
  16. return deduplicated_list
  17. if __name__ == '__main__':
  18. # Example usage
  19. tokens = ["token1", "token2", "token1", "token3", "token2", "token4"]
  20. deduplicated_tokens = deduplicate_tokens(tokens)
  21. print(deduplicated_tokens) # Output: ['token1', 'token2', 'token3', 'token4']

Add your comment