list - How to stack indices and given values -
seq1_values = [5, 40, 180, 13, 30, 20, 25, 24, 29, 31, 54, 46, 42, 50, 67, 17, 76, 33, 84, 35, 100, 37, 110, 32, 112, 15, 123, 3, 130, 42] def get_num_values(): global seq1_values return len( seq1_values ) def get_values(): global seq1_values value in seq1_values: yield value yield none def next_value(): return next( next_value.values ) next_value.values = get_values() def main(): numbers = [] value = next_value() while value not none: numbers.append(value) input_size = len(numbers)-1 in range(input_size): print("|", str(input_size).rjust(4), end="") j in range(input_size): print("|", str(value).rjust(4), end="") value = next_value() main()
output supposed this:
| 0| 1| 2| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| 30| | 5| 40| 180| 13| 30| 20| 25| 24| 29| 31| 54| 46| 42| 50| 67| 17| 76| 33| 84| 35| 100| 37| 110| 32| 112| 15| 123| 3| 130| 42|
your question not super clear, understand, looking for:
>>> def myprint(l): ... maxlen = max(len(str(n)) n in l) ... print ("|", "|".join(" "*(maxlen-len(str(i))) + str(i) in range(len(l))) + "|") ... print ("|", "|".join(" "*(maxlen-len(str(n))) + str(n) n in l) + "|") ... >>> myprint([5, 40, 180, 13, 30, 20, 25, 24, 29, 31, 54, 46, 42, 50, 67, 17, ... 76, 33, 84, 35, 100, 37, 110, 32, 112, 15, 123, 3, 130, 42]) | 0| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 27| 28| 29| | 5| 40|180| 13| 30| 20| 25| 24| 29| 31| 54| 46| 42| 50| 67| 17| 76| 33| 84| 35|100| 37|110| 32|112| 15|123| 3|130| 42|
Comments
Post a Comment