bgneal@10: """Chapter 2.7, exercise 7. bgneal@10: bgneal@10: Write a generator that yields an infinite sequence of alpha-numeric identifiers, bgneal@10: starting with a1 through z1, then a2 through z2, and so on. bgneal@10: bgneal@10: """ bgneal@10: import string bgneal@10: bgneal@10: def generate_identifier(): bgneal@10: num = 1 bgneal@10: while True: bgneal@10: for c in string.lowercase: bgneal@10: yield c + str(num) bgneal@10: num += 1 bgneal@10: bgneal@10: bgneal@10: if __name__ == '__main__': bgneal@10: try: bgneal@10: for name in generate_identifier(): bgneal@10: print name bgneal@10: except KeyboardInterrupt: bgneal@10: print "Control-C interrupt"