You need to get a list with all palindrome numbers in the range from 100 to 1000. This problem can be solved in two ways:
- Check the first and last digits of the number, and if they match, write them to the list.
palindromes = [n for n in range(100, 1000) if n // 100 == n % 10]
print(palindromes)
- Convert the number to a string and check it with its "inverted" copy.
palindromes = [i for i in range(100, 1001) if str(i) == str(i)[::-1]]
print(palindromes)
Question: Which of these methods is preferable (interpreted faster or takes up less PC resources) and which one is better to use?