Похожие чаты

Hi guys, i am rewriting my old code and did

a refactoring like this:
https://www.toptal.com/developers/hastebin/igutaripac.py

however, it got me thinking: is there a way to make the variable = variant1 or variant2 or variant3 or ... expression more concise?
i suppose i can write my own function like this:
def multiple_or(*args):
if len(args) == 1:
return args[0]
return multiple_or(*(args[:-1])) or args[-1]

but, is there a built-in function that does that?

10 ответов

9 просмотров

any(...)

artemetra 🇺🇦-[less active] Автор вопроса
drunktimelord
any(...)

any returns a bool though, i need the item

You can also use itertools: from itertools import dropwhile from operator import not_ def multiple_or(seq, default=None): return next(dropwhile(not_, seq), default) You can also check out the "first_true" definition here: https://docs.python.org/3/library/itertools.html?highlight=iter#itertools-recipes

artemetra 🇺🇦-[less active] Автор вопроса
harꭑony5 🐦‍🔥 ↺
You can also use itertools: from itertools import...

why import operator.not from operator import not and import operator operator.not is throwing syntax error

Похожие вопросы

Обсуждают сегодня

Здравствуйте! Есть вопросы по ПК: 1.1. Безопасно ли запускать программы, которым я не доверяю, в виртуальной машине под KVM+qemu? (x86_64) 1.2. То же самое при использовании ...
Pavel
5
Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
У меня вопрос, а какой уровень оптимизации ставить при сборке на i5 4 ядра 16G ddr3 ОЗУ и видюха Geforce GTX 970?
Sir Jiga
18
Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
37
Happy Friday and happy CartesiWeekly! This week on the list: 🪲 Bug Buster Update 🎥 Erick de Moura’s interview with Ornella from Web3TV 👽 Thriving Cartesi alien 🇧🇷 SBRC hackat...
Nida | Cartesi - Never DM first or ask for funds!
1
Oh.... Admins at the main TG is already muted me. How many months Sir you muted me? Or forever if you are here @Janevietani @JohnnySonic
Charles Dar
28
Вот еще криповенькая штука. uMain.pas(517,3) Warning: Case statement does not handle all possible cases И ЧО? 😂
Александр (Rouse_) Багель
20
комрады, че-та лыжы не едут var tmpFont: TFont; begin tmpFont:= TFont.Create; try case rgFontColor.ItemIndex of 0: tmpFont.Color:= clWindowText; 1: tmpFo...
Ed Doc
34
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
.model small .stack 100h .data a db 'Hello, World!', '$' ; исходная строка b db 20 dup(?) ; строка b с запасом на максимальную длину .code main: ...
Алексей -man
3
Карта сайта