next alpha sequence value from var pointing to array
Hello, I am still fairly new to python, but find it to be a great scripting language.Here is my issue: I am attempting to utilize a function to receive any sequence of letter characters and return to me the next value in alphabetic order e.g. send in "abc" get back "abd".I found a function on StackExchange (Rosenfield, A 1995) that seems to work well enough (I think): /def next(s):/ /strip_zs = s.rstrip('z')/ /if strip_zs:/ /return strip_zs[:-1] + chr(ord(strip_zs[-1]) + 1) + 'a' * (len(s) - len(strip_zs))/ /else:/ /return 'a' * (len(s) + 1)/ I have found this function works well if I call it directly with a string enclosed in quotes: returnValue = next("abc") However, if I call the function with a variable populated from a value I obtain from an array[] it fails returning only ^K Unfortunately, because I don't fully understand this next function I can't really interpret the error.Any help would be greatly appreciated. Thanks ahead of time, Derek -- http://mail.python.org/mailman/listinfo/python-list
Re: next alpha sequence value from var pointing to array
Hi Peter, Thanks for you feedback. I have the next_alpha function you have provided. But, am still getting the same result. The actual value I am passing in is "btl". But, as I mentioned I am getting it from an array value. Here is my actual code. I am reading a comma separated file, getting the last item and trying to get the next alpha. Thanks again. def getNRTLid(layerName): lids_seen = [] lyrs_seen = [] last_lid = "" f = open("NRTLayerLID.csv", "r"); for line in f: sp = line.split(',') lyrs_seen.append(sp[0]) lids_seen.append(sp[1]) f.close(); sorted_array = sorted(lids_seen) sorted_array.reverse() print "highest lid is %s" % sorted_array[0] highest_lid = sorted_array[0] test = highest_lid.lower() nl = next_alpha(test) Best, Derek -- http://mail.python.org/mailman/listinfo/python-list
Re: next alpha sequence value from var pointing to array
Newline was the issue indeed. Thanks for you help Peter. Cheers, Derek -- http://mail.python.org/mailman/listinfo/python-list