I\'ve got a Perl function which takes a timestamp and returns either the unchanged timestamp (if it\'s never seen it before) or otherwise, it appends some letters to make it uni
Quite similar to Ali A, but I'll post mine anyway:
class unique_timestamp:
suffixes = " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def __init__(self):
self.previous_timestamps = {}
pass
def uniquify(self, timestamp):
times_seen_before = self.previous_timestamps.get(timestamp, 0)
self.previous_timestamps[timestamp] = times_seen_before + 1
if times_seen_before > 0:
return str(timestamp) + self.suffixes[times_seen_before]
else:
return str(timestamp)
Usage:
>>> u = unique_timestamp()
>>> u.uniquify(1)
'1'
>>> u.uniquify(1)
'1A'
>>> u.uniquify(1)
'1B'
>>> u.uniquify(2)
'2'