compare two python strings that contain numbers

前端 未结 5 1520
礼貌的吻别
礼貌的吻别 2020-12-19 11:29

UPDATE: I should have specified this sooner, but not all of the names are simply floats. For example, some of them are \"prefixed\" with \"YT\". So for example\" YT1.1. so,

5条回答
  •  孤城傲影
    2020-12-19 12:24

    use s1.split(".") to create a list of the items before and after the decimal then sort the list of lists, example:

    import random
    sheets = list([str(x), str(y)] for x in xrange(1, 5) for y in xrange(0,99))
    print sheets
    #sheets in order
    random.shuffle(sheets)
    print sheets
    #sheets out of order
    sheets.sort()
    print sheets
    #sheets back in order
    

    So, you implementation might be:

    #assume input sheets is a list of the worksheet names
    sheets = list(x.split(".") for x in input_sheets)
    sheets.sort()
    

提交回复
热议问题