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: |

Friday’s performance was part of a larger shift. For the week, the Dow, S&P 500 and Nasdaq fell 2%, 2.9%, and 3.5%, respectively. Channels are not fully encrypted, end-to-end. All communications on a Telegram channel can be seen by anyone on the channel and are also visible to Telegram. Telegram may be asked by a government to hand over the communications from a channel. Telegram has a history of standing up to Russian government requests for data, but how comfortable you are relying on that history to predict future behavior is up to you. Because Telegram has this data, it may also be stolen by hackers or leaked by an internal employee. So, uh, whenever I hear about Telegram, it’s always in relation to something bad. What gives? The S&P 500 fell 1.3% to 4,204.36, and the Dow Jones Industrial Average was down 0.7% to 32,943.33. The Dow posted a fifth straight weekly loss — its longest losing streak since 2019. The Nasdaq Composite tumbled 2.2% to 12,843.81. Though all three indexes opened in the green, stocks took a turn after a new report showed U.S. consumer sentiment deteriorated more than expected in early March as consumers' inflation expectations soared to the highest since 1981. "We're seeing really dramatic moves, and it's all really tied to Ukraine right now, and in a secondary way, in terms of interest rates," Octavio Marenzi, CEO of Opimas, told Yahoo Finance Live on Thursday. "This war in Ukraine is going to give the Fed the ammunition, the cover that it needs, to not raise interest rates too quickly. And I think Jay Powell is a very tepid sort of inflation fighter and he's not going to do as much as he needs to do to get that under control. And this seems like an excuse to kick the can further down the road still and not do too much too soon."
from hk


Telegram Python/ django
FROM American