数字的数字按升序排列。 (比较)

时间:2016-03-18 13:54:08

标签: python

cc = input('Input the number: ')
b = str(cc)
c = []
for digit in b:
    c.append (int(digit))
    csort = c.sort(key=int)
    c == csort #??

如果号码是按升序排列,我需要说TrueFalse

我的代码无法打印TrueFalse,为什么?

1 个答案:

答案 0 :(得分:0)

您不应在 make[2]: Entering directory '/home/daniel/repo/AdaLab' /usr/bin/cmake -E cmake_progress_report /home/daniel/repo/AdaLab/CMakeFiles 31 Putting child 0x1d014c0 (src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o) PID 11603 on the chain. Live child 0x1d014c0 (src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o) PID 11603 [ 88%] Reaping winning child 0x1d014c0 PID 11603 Live child 0x1d014c0 (src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o) PID 11604 Building CXX object src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o Reaping winning child 0x1d014c0 PID 11604 cd /home/daniel/repo/AdaLab/src/general/test && /usr/bin/c++ -std=c++0x -lstdc++ -lm -I/home/daniel/repo/AdaLab -I/home/daniel/repo/AdaLab/mips_release/local/include -I/usr/lib/openmpi/include -I/usr/lib/openmpi/include/openmpi -I/usr/share/R/include -I/home/daniel/R/x86_64-pc-linux-gnu-library/3.2/Rcpp/include -I/home/daniel/R/x86_64-pc-linux-gnu-library/3.2/RInside/include -I/home/daniel/repo/AdaLab/inspector -I/home/daniel/repo/AdaLab/data -o CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o -c /home/daniel/repo/AdaLab/src/general/test/testGeneralFunctions.cpp Live child 0x1d014c0 (src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o) PID 11606 Reaping losing child 0x1d014c0 PID 11606 src/general/test/CMakeFiles/testGeneralFunctions.dir/build.make:54: recipe for target 'src/general/test/CMakeFiles/testGeneralFunctions.dir/testGeneralFunctions.cpp.o' failed Removing child 0x1d014c0 PID 11606 from chain. make[2]: Leaving directory '/home/daniel/repo/AdaLab' Reaping losing child 0x1e521d0 PID 11602 CMakeFiles/Makefile2:1031: recipe for target 'src/general/test/CMakeFiles/testGeneralFunctions.dir/all' failed Removing child 0x1e521d0 PID 11602 from chain. make[1]: Leaving directory '/home/daniel/repo/AdaLab' Reaping losing child 0xd9b960 PID 11242 Makefile:126: recipe for target 'all' failed Removing child 0xd9b960 PID 11242 from chain. 中使用key=int因为c.sort(key=int)已经是c的列表,因为您通过int创建了c.append(int(digit))

但关键问题是c.sort()就位,因此会返回None,而是使用sorted返回已排序的list

csort = sorted(c)

然后你可以通过以下方式打印比较的布尔结果:

print c == csort