是否有更优雅/ pythonic的方式来表达这个结构?

Tos*_*hio 1 python list

itemList = ["a","b","c","d","e","f","g","h"]
aa = "NULL"
bb = "NULL"
cc = "NULL"
for item in itemList:
    aa = bb
    bb = cc
    cc = item
    if aa == "NULL":
        continue
    print "%s_%s_%s" % (aa, bb, cc)
Run Code Online (Sandbox Code Playgroud)

Sil*_*ost 9

>>> ['_'.join(itemList[i:i+3]) for i in range(len(itemList)-2)]
['a_b_c', 'b_c_d', 'c_d_e', 'd_e_f', 'e_f_g', 'f_g_h']
Run Code Online (Sandbox Code Playgroud)

或者如果你坚持打印:

>>> for i in range(len(itemList)-2):
    print('_'.join(itemList[i:i+3]))
Run Code Online (Sandbox Code Playgroud)