A list called numbers
, includes all prime integers from 1 to 1000. I want to check if a number includes "1" or "7", and if so, remove it from the list numbers
for number in numbers:
number = (list(str(number)))
if any(x in list(str(number)) for x in ("1" or "7")):
number = [int(i) for i in number]
number = (''.join(str(i) for i in number))
numbers.remove(int(number))
print(number)
The problem is, that it is semi-functional. Results are:
1 11 15 19 31 41 51 61 71 81 91 101 105 109 113 117 121 125 129 133 137 141 145 149 153 157 161 165 169 173 177 181 185 189 193 197 201 211 215 219 231 241 251 261 271 281 291 301 311 315 319 331 341 351 361 371 381 391 401 411 415 419 431 441 451 461 471 481 491 501 511 515 519 531 541 551 561 571 581 591 601 611 615 619 631 641 651 661 671 681 691 701 711 715 719 731 741 751 761 771 781 791 801 811 815 819 831 841 851 861 871 881 891 901 911 915 919 931 941 951 961 971 981 991
Expected result is all numbers which include "1" or "7" E.G 7, 17, 37, 107 and so on.
Why is this happening?
Aucun commentaire:
Enregistrer un commentaire