iterating over list and concatenating alphabetical sequence in Python -
I am trying to iterate on a list and trying to specify the character letter of each element within the list And if a duplicate assigns the next letter in the alphabet to get the unique letter.
sequence = [0, 1, 2, 3, 1, 4, 2, 1] unique_sec = [0a, 1a, 2a, 3a, 1b, 4a, 2B, 1C] I tried to prepare a list of alphabet letters like this:
alpha = list (map (CR, border) (65, 91))) Then I wanted to iterate on sequence like this:
In sequence for me: unique_seq.append (i ) In the sequence if i do not have unique_seq other i I'm not sure how to know about the rest ...
Thanks D,
Here is a solution that will work with the sequence of infinite shapes and with infinite numbers ( Defining increment_item (item = 'A'): '' 'In view of a character sequence item, the character produces the next item in the sequence set: Type object: str: param item: Character sequence item to increase: rtype: str: return: next element in sequence ex: item = 'a', return = 'b' item = 'z', index in index [= 1], return = 'AA' '' 'next_chart = [ord (four)] for all in the object next_char [-1] + = 1 in the xrange (lane (next_teach) -1, -1, - 1): if next_char [index] & gt; Ord ('z'): next_chart [index] = ind ('a') if index & gt; 0: next_char [index-1] + = 1 other: next_char.append (ord ('a')) returns ''. (Four (four) four for four in the next four (four) DEF char_generator (start = 'A'): '' 'A generator which produces the next sequence in each item next sequence is called: Type Start: str: param start: The starting object for the generator sequence '' 'current = start is correct when starting the yield: current = increment_item (current) yield current def build_unique_sequence (sequence):' '' In view of an input sequence, Returns the same sequence, such as back in sequence Each element is unique: type sequence: list: ultimate sequence: make the sequence unique: rtype: list: return: the resulting unique sequence pre: sequence = [0, 1, 2, 3, 1, 4, 2, 1], return = ['0', '1A', '2A', '3A', '1B', '4A', '2B', '1C'] '' 'key_set = dec (item, four_janerator )] For the item in the set (sequence) Return map (Lambda item: '{} {}'. Format (item, key_set [item] .next ()), sequence)
What are the results:
>>>> ['0', '1a', '2A', '3A', '1B' '4A', 2 Minister ',' 1 ', 1A, 2, 3, 1, 4, 2, 1] 1C']
Comments
Post a Comment