名为numbers
的列表,包括1到1000之间的所有素数。列表numbers17
与numbers
具有相同的数字。
我想检查一个号码是否包括" 1"或" 7",如果是,请将其从列表numbers
中删除:
for number in numbers17:
number = (list(str(number)))
if any(x in list(str(number)) for x in ("1", "7")):
number = [int(i) for i in number]
number = (''.join(str(i) for i in number))
numbers.remove(int(number))
print(number)
问题是它是半功能的。 结果是:
2, 3, 5, 9, 13, 17, 21, 23, 25, 29, 33, 35, 39, 43, 45, 49, 53, 55, 59, 63, 65, 69, 73, 77, 81, 83, 85, 89, 93, 95, 99, 103, 107, 111, 115, 119, 123, 127, 131, 135, 139, 143, 147, 151, 155, 159, 163, 167, 171, 175, 179, 183, 187, 191, 195, 199, 203, 205, 209, 213, 217, 221, 223, 225, 229, 233, 235, 239, 243, 245, 249, 253, 255, 259, 263, 265, 269, 273, 277, 281, 283, 285, 289, 293, 295, 299, 303, 305, 309, 313, 317, 321, 323, 325, 329, 333, 335, 339, 343, 345, 349, 353, 355, 359, 363, 365, 369, 373, 377, 381, 383, 385, 389, 393, 395, 399, 403, 405, 409, 413, 417, 421, 423, 425, 429, 433, 435, 439, 443, 445, 449, 453, 455, 459, 463, 465, 469, 473, 477, 481, 483, 485, 489, 493, 495, 499, 503, 505, 509, 513, 517, 521, 523, 525, 529, 533, 535, 539, 543, 545, 549, 553, 555, 559, 563, 565, 569, 573, 577, 581, 583, 585, 589, 593, 595, 599, 603, 605, 609, 613, 617, 621, 623, 625, 629, 633, 635, 639, 643, 645, 649, 653, 655, 659, 663, 665, 669, 673, 677, 681, 683, 685, 689, 693, 695, 699, 703, 707, 711, 715, 719, 723, 727, 731, 735, 739, 743, 747, 751, 755, 759, 763, 767, 771, 775, 779, 783, 787, 791, 795, 799, 803, 805, 809, 813, 817, 821, 823, 825, 829, 833, 835, 839, 843, 845, 849, 853, 855, 859, 863, 865, 869, 873, 877, 881, 883, 885, 889, 893, 895, 899, 903, 905, 909, 913, 917, 921, 923, 925, 929, 933, 935, 939, 943, 945, 949, 953, 955, 959, 963, 965, 969, 973, 977, 981, 983, 985, 989, 993, 995, 999
预期结果是所有数字包括" 1"或" 7" E.G:17,177,717等等。
为什么会这样?