Telegram Group & Telegram Channel
🐍 Задача на Python: "Исчезающая цифра"

Условие:
У тебя есть список строк — чисел от 1 до 100, но одно из чисел случайно пропало.
Найди, какое число отсутствует. Нельзя использовать sum(), sorted(), Counter. Все числа в списке представлены как строки.

Пример:


import random

original = [str(i) for i in range(1, 101)]
missing = random.choice(original)
shuffled = original.copy()
shuffled.remove(missing)
random.shuffle(shuffled)


Напиши функцию:


def find_missing_number(data: list[str]) -> int:
...


📌 Подвох:
Нельзя просто сложить строки. Но можно использовать свойство XOR:


a ^ a = 0
0 ^ b = b


То есть: если мы сделаем XOR всех чисел от 1 до 100, а затем XOR всех чисел в переданном списке — результатом будет пропущенное число.

🧠 Решение:

```python
def find_missing_number(data: list[str]) -> int:
xor_full = 0
xor_data = 0

for i in range(1, 101):
xor_full ^= i

for val in data:
xor_data ^= int(val)

return xor_full ^ xor_data
```

Пояснение:
-
xor_full — XOR всех чисел от 1 до 100.
-
xor_data — XOR всех чисел в текущем списке (`str` → `int`).
- Разность
xor_full ^ xor_data вернёт единственное отсутствующее число.

🎯 Пример использования:

```python
original = [str(i) for i in range(1, 101)]
original.remove("42")
random.shuffle(original)

print(find_missing_number(original)) # → 42
```

🔥 Эта задача хороша тем, что:
• содержит хитрый запрет на
sum()
• требует знания побитовых операций
• работает с типами (`str` vs `int`)
• подходит для собеседования уровня middle+

@pythonl



group-telegram.com/pythonl/4819
Create:
Last Update:

🐍 Задача на Python: "Исчезающая цифра"

Условие:
У тебя есть список строк — чисел от 1 до 100, но одно из чисел случайно пропало.
Найди, какое число отсутствует. Нельзя использовать sum(), sorted(), Counter. Все числа в списке представлены как строки.

Пример:


import random

original = [str(i) for i in range(1, 101)]
missing = random.choice(original)
shuffled = original.copy()
shuffled.remove(missing)
random.shuffle(shuffled)


Напиши функцию:


def find_missing_number(data: list[str]) -> int:
...


📌 Подвох:
Нельзя просто сложить строки. Но можно использовать свойство XOR:


a ^ a = 0
0 ^ b = b


То есть: если мы сделаем XOR всех чисел от 1 до 100, а затем XOR всех чисел в переданном списке — результатом будет пропущенное число.

🧠 Решение:

```python
def find_missing_number(data: list[str]) -> int:
xor_full = 0
xor_data = 0

for i in range(1, 101):
xor_full ^= i

for val in data:
xor_data ^= int(val)

return xor_full ^ xor_data
```

Пояснение:
-
xor_full — XOR всех чисел от 1 до 100.
-
xor_data — XOR всех чисел в текущем списке (`str` → `int`).
- Разность
xor_full ^ xor_data вернёт единственное отсутствующее число.

🎯 Пример использования:

```python
original = [str(i) for i in range(1, 101)]
original.remove("42")
random.shuffle(original)

print(find_missing_number(original)) # → 42
```

🔥 Эта задача хороша тем, что:
• содержит хитрый запрет на
sum()
• требует знания побитовых операций
• работает с типами (`str` vs `int`)
• подходит для собеседования уровня middle+

@pythonl

BY Python/ django


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/pythonl/4819

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

Investors took profits on Friday while they could ahead of the weekend, explained Tom Essaye, founder of Sevens Report Research. Saturday and Sunday could easily bring unfortunate news on the war front—and traders would rather be able to sell any recent winnings at Friday’s earlier prices than wait for a potentially lower price at Monday’s open. Given the pro-privacy stance of the platform, it’s taken as a given that it’ll be used for a number of reasons, not all of them good. And Telegram has been attached to a fair few scandals related to terrorism, sexual exploitation and crime. Back in 2015, Vox described Telegram as “ISIS’ app of choice,” saying that the platform’s real use is the ability to use channels to distribute material to large groups at once. Telegram has acted to remove public channels affiliated with terrorism, but Pavel Durov reiterated that he had no business snooping on private conversations. The SC urges the public to refer to the SC’s I nvestor Alert List before investing. The list contains details of unauthorised websites, investment products, companies and individuals. Members of the public who suspect that they have been approached by unauthorised firms or individuals offering schemes that promise unrealistic returns "We as Ukrainians believe that the truth is on our side, whether it's truth that you're proclaiming about the war and everything else, why would you want to hide it?," he said. "Your messages about the movement of the enemy through the official chatbot … bring new trophies every day," the government agency tweeted.
from sa


Telegram Python/ django
FROM American