Функция sub в regex может принимать функцию в качестве аргумента repl.
📄 Из документации:
If repl is a function, it is called for every non-overlapping occurrence of pattern. The function takes a single match object argument, and returns the replacement string.
То есть для каждого совпадения будет вызвана функция для вычисления замены вместо замены на одну и ту же строку для всех совпадений.
Иными словами, для замены разных совпадений на разные строки не потребуется запускать re.sub() много раз для каждой строки замены. Достаточно определить функцию, которая вернёт строку для каждого из совпадений.
Описание слишком запутанное🤔, давайте лучше рассмотрим на простом примере:
Создаем карту замены. То есть какие строки на какие требуется менять.
remap = {
'раз': '1',
'два': '2',
'три': '3',
'четыре': '4',
'пять': '5',
}
Пишем функцию поиска строки для замены. Единственным аргументом будет объект re.Match.
Используя данные этого объекта мы вычисляем замену on-the-fly!
def get_str(match: re.Match):
word = match.group(1)
return remap.get(word.lower()) or word
Пример текста.
text = '''Раз Два Три Четыре Пять
Вместе будем мы считать
Пять Четыре Три Два Раз
Мы считать научим вас
'''
Теперь запускаем re.sub и вместо строки замены (repl) подаём имя функции.
(Данный паттерн ищет отдельные слова в тексте)
>>> print(re.sub(r'(\w+)', get_str, text))
1 2 3 4 5
Вместе будем мы считать
5 4 3 2 1
Мы считать научим вас
Думаю, достаточно наглядно 🤓
#libs#regex
🐠 Kingfisher traders, wanna snag the BIGGEST $BTC fishes? 🐦
Use the GEX "sonar" chart, and look at the options whales!
🔵 Blue water = Calm fishing, easy gains.
🔴 Red water = Choppy, risky dives.
⚪️ Clear water? ⚠️ Big moves brewing, watch for any change in weather!
#BTC#GEX#CryptoTrading#OptionsTrading
BIT Exchange has launched the world’s 1st #ADA/USD #OptionsTrading🥳
▫️Denominated & settled in USD
▫️1-10x leverage
▫️Available on web, mobile app & API
▫️More #altcoin options are coming
We are excited to be part of this strategic collaboration with BIT and Darley Technologies to make #ADAOptionsTrading possible ✨
Read more here.
🚀 Booked ₹1.37+ Lakh Profit! 💰
Another great day in the markets with smart entries & exits. 📈
Check out the power of precision trading! 🔥
🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast.
👇 Click to join now
🔗https://t.me/+7emcw1k0H_U4ZDg9
📊 Stay ahead, trade smart. 💯
#BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits
🚀 Booked ₹1.37+ Lakh Profit! 💰
Another great day in the markets with smart entries & exits. 📈
Check out the power of precision trading! 🔥
🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast.
👇 Click to join now
🔗https://t.me/+7emcw1k0H_U4ZDg9
📊 Stay ahead, trade smart. 💯
#BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits
🚀 Booked ₹1.37+ Lakh Profit! 💰
Another great day in the markets with smart entries & exits. 📈
Check out the power of precision trading! 🔥
🧠 Join my private trading community for real-time insights, setups, and mentorship. Whether you're new or experienced — you’ll level up fast.
👇 Click to join now
🔗https://t.me/bankniftygo
📊 Stay ahead, trade smart. 💯
#BankNifty#OptionsTrading#StockMarketIndia#TradeLab#Profits
https://x.com/priceactiongann/status/1810583536312647828
#nifty#BankNifty
my personal rules i see before taking trades, few of them have posted here!
my recent research studies going on about time!
make notes and study!
trading is easy but work behind the scenes is the real work done, sharpen Ur skills and study always!
#trading#priceaction#stockmarket#nifty50#OptionsTrading#research
https://x.com/priceactiongann/status/1810583536312647828
https://x.com/priceactiongann/status/1806296904663228873
#nifty
23910 done in nifty #timecycle helped from 24 th,
price will decide here now, OLHC etc.
weekly price close will be very interesting!
, when #banknifty reaches 54583 u will see some magic! wait and see!
#stocks#stockmarket#stockmarketindia#gann#OptionsTrading
https://x.com/priceactiongann/status/1837115028920476072
#nifty50#banknifty
1.First of all Congrats if u have foreseen this well in advance! then congrats to other researchers and forecasters here!
keep it up! 🔮👏
2.Once it breached today bank nifty and nifty it is officially in new zone of cycle which is helping bank nifty cycle to complete! 📈🚀
(its not in my edge and after it crossed it confirmed my research )
3.Nifty Level Next Top Deciding 26010 and 26175! 📍
which coincides with bank nifty level 54583.60! 📍
We CANNOT IGNORE THE OBVIOUS UPSIDE levels!
4.THIS AREA or particular above 25300 IS NOT IN Ours ZONE AT ALL OR OUR EDGE
(so we ignored upside at all costs as we focus on selective areas only which iam good at)
5.THIS EXTRA ZONE above the 25300 and 25192 is BECAUSE OF BANK NIFTY CYCLES TRYING TO COMPLETE its own cycle to 54583.60.
6.Both corelating to complete it!(which is missed to see)(will do better work and update next time considering all elements)
7.In gold i see only one cycle but in this case may be another one similar to nifty like gift nifty bank nifty , Sensex all plays crucial role and validates and helps each other markets too.(trust me ,too much of work doing all these) 🌟
Every time when long term levels coincides with nifty and bank nifty it gave us at least 500 to 800 points
8.Many mistakes were done by looking very shorter term or in a short term for Long term targets.
just iam looking few 500 plus points once price is reached. sensible way to grab the vibrations.
9.Bank nifty averages 1000 to 2000 points when confluence and big levels are reached.📊
(51860 we saw 2000 points drop last time and if taken from last top to bottom it was 3600 points compared to nifty bank nifty is real good movements)📊
10.When during learning phase more winning will only boost your ego, losing will give u lots of learning.
iam trying to learn at the same time lose less too.
11.All the short term cycles recent times in nifty and bank nifty as marked in charts holded for short time but taken out again easily next day,closing above and retest on top to go up more.(look charts)
same cycles as nifty , bank nifty cycles
1.56268
2.54583
3.54400
4.51860 📝
12.if u still think the levels wont work 23900 or 23535(longer term levels for months years to come)
my work is sometimes short term cycles but i see very much ahead in future, it is must for every trader to learn such long term skills. 🗺
13.WHICH NEVER FAILED IN PAST SO SOONER OR LATER THIS ENTIRE 23900 AND 23535 SHOULD BE REACHED FOR LONGER TERM FOR SURE.
when this cycle fails either it takes on top and go up and again it will go back to where it started so given levels in long term is surely pending downside!(thats y levels are called deciding levels, so it vibrates and decides there) 🔄
14.KEEP THIS FOR VERY LONG TERM AND EVERY LEVEL IS CONFIRMATION AND DECIDING FOR SURE.
All my analysis are not signals or recommendation so trade or use at ur own risk here, i post my studies and research here only!⚠️
Thanks for the support always, please do like and repost to many, More updates are upcoming.
#stocks#nifty50#stock#stockmarket#OptionsTrading#trading#gann#priceaction#stockmarkets#StockMarketNews
#StockMarketIndia
https://x.com/priceactiongann/status/1837115028920476072