我写了这个类来压缩和扩展数字列表到序列字符串,包括步长值大于1时的步骤值.代码仍然感觉笨重.是否有可以执行此类操作的库?可能更简单的代码?
import re
class Foo( object ):
def __init__( self, num_list ):
self.num_list = sorted( list( set( [ int(n) for n in num_list ] ) ) )
# end def __init__
def gen_seq_data( self ):
self.seq_data = list()
index_offset = None
backward_step_value = None
forward_step_value = None
sub_list = list()
sub_list_step_value = None
for index, num in enumerate( self.num_list ):
if index - 1 < 0:
backward_step_value = None
# end if
else:
backward_step_value = num - self.num_list[ index - …Run Code Online (Sandbox Code Playgroud) python ×1