Python Codes
رفتن به کانال در Telegram
This channel will serve you all the codes and programs which are related to Python. We post the codes from the beginner level to advanced level.
نمایش بیشتر7 090
مشترکین
اطلاعاتی وجود ندارد24 ساعت
اطلاعاتی وجود ندارد7 روز
اطلاعاتی وجود ندارد30 روز
آرشیو پست ها
7 090
👋 Welcome to @datastructuresandalgoofficial 👋
To get job in top tech companies like 𝙂𝙤𝙤𝙜𝙡𝙚, 𝘼𝙢𝙖𝙯𝙤𝙣, 𝙈𝙞𝙘𝙧𝙤𝙨𝙤𝙛𝙩, 𝙁𝙖𝙘𝙚𝙗𝙤𝙤𝙠, 𝙚𝙩𝙘 you must know 𝘿𝙖𝙩𝙖 𝙎𝙩𝙧𝙪𝙘𝙩𝙪𝙧𝙚𝙨 𝙖𝙣𝙙 𝘼𝙡𝙜𝙤𝙧𝙞𝙩𝙝𝙢𝙨. And for excelling in tech field you should know 𝘿𝙖𝙩𝙖 𝙎𝙩𝙧𝙪𝙘𝙩𝙪𝙧𝙚𝙨 𝙖𝙣𝙙 𝘼𝙡𝙜𝙤𝙧𝙞𝙩𝙝𝙢𝙨.
In this Channel you will get all materials related Data Structures and Algorithms(DSA).
𝙁𝙤𝙧 𝙡𝙚𝙖𝙧𝙣𝙞𝙣𝙜 𝘿𝙖𝙩𝙖 𝙎𝙩𝙧𝙪𝙘𝙩𝙪𝙧𝙚𝙨 𝙖𝙣𝙙 𝘼𝙡𝙜𝙤𝙧𝙞𝙩𝙝𝙢𝙨(𝘿𝙎𝘼) 𝙛𝙤𝙧 𝙛𝙧𝙚𝙚 𝙟𝙤𝙞𝙣 𝙤𝙪𝙧 𝙩𝙚𝙡𝙚𝙜𝙧𝙖𝙢 𝙘𝙝𝙖𝙣𝙣𝙚𝙡:
https://t.me/datastructuresandalgoofficial
So what are you waiting for?
Join right now👍
https://t.me/datastructuresandalgoofficial
7 090
Join our other channels
And get the Best Content
For Basic Electronics : @BasicElectronics
For Python Learning: @Python_Codes
For Python Books : @PythonEbookz
For Knowledge: @TerrificKnowledge
For learning Basics: @BasicsToKnow
For Placements : @Aptitude_Tricky
What's Special Today:
@whatstodays_special
Udemy Channel: @udemy_channel
7 090
Sorts one list based on another list containing the desired indexes.
Use zip() and sorted() to combine and sort the two lists, based on the values of indexes.
Use a list comprehension to get the first element of each pair from the result.
Use the reverse parameter in sorted() to sort the dictionary in reverse order, based on the third argument.
CODE:
def sort_by_indexes(lst, indexes, reverse=False):
return [val for (_, val) in sorted(zip(indexes, lst), key=lambda x: \
x[0], reverse=reverse)]
Example:
a = ['eggs', 'bread', 'oranges', 'jam', 'apples', 'milk']
b = [3, 2, 6, 4, 1, 5]
sort_by_indexes(a, b)
Output: ['apples', 'bread', 'eggs', 'jam', 'milk', 'oranges']
sort_by_indexes(a, b, True)
Output: ['oranges', 'milk', 'jam', 'eggs', 'bread', 'apples']
Share and Support
@Python_Codes7 090
Learn from Technical Ravi
Educational Stock Marketing Channel
Can take calls for free and accurate results
Join Now
https://t.me/TechnicalTraderRAVI
7 090
FROM NOW, DONT WORRY WE GOT MR. RAVI HAVING MORE THAN 5 YEARS OF EXPERIENCE, TO SOLVE ALL YOUR PROBLEMS REGARDING STOCK MARKET ... ! 🤑
HE HAS HIS OWN FREE EDUCATIONAL CHANNEL WHERE HE PROVIDES FREE IMPORTANT UPDATES AND TIPS FOR INTRADAY TRADING AND INVESTMENT ADVICE ...! 🕴🕺
MOST OF THE PEOPLE ARE EARNING REGULARLY FROM HIS CHANNEL. 🤩
JOIN THE BELOW LINK NOW AND LET YOUR MONEY WORK WHILE YOU SLEEP 😇
Join Now
https://t.me/TechnicalTraderRAVI
7 090
Converts a string to kebab case.
👉Use re.sub() to replace any - or _ with a space, using the regexp r"(_|-)+".
👉Use re.sub() to match all words in the string, str.lower() to lowercase them.
👉Finally, use str.join() to combine all word using - as the separator.
CODE:
from re import sub
def kebab(s):
return '-'.join(
sub(r"(\s|_|-)+"," ",
sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+",
lambda mo: ' ' + mo.group(0).lower(), s)).split())
Examples
kebab('camelCase') # 'camel-case'
kebab('some text') # 'some-text'
kebab('some-mixed_string With spaces_underscores-and-hyphens')
# 'some-mixed-string-with-spaces-underscores-and-hyphens'
kebab('AllThe-small Things') # 'all-the-small-things'
Share and Support
@Python_Codes7 090
bifurcate_by
Splits values into two groups, based on the result of the given filtering function.
👉Use a list comprehension to add elements to groups, based on the value returned by fn for each element.
👉If fn returns a truthy value for any element, add it to the first group, otherwise add it to the second group.
CODE:
def bifurcate_by(lst, fn):
return [
[x for x in lst if fn(x)],
[x for x in lst if not fn(x)]
]
Examples
Input:
bifurcate_by(['beep', 'boop', 'foo', 'bar'], lambda x: x[0] == 'b')
Output:
[ ['beep', 'boop', 'bar'], ['foo'] ]
Share and Support
@Python_Codes
7 090
What are named tuples in Python?
These are part of the collections module and act very similar to regular tuples
The main difference being that values stored in a named tuple can be accessed using field names instead of indexes.
For example, a point in the two-dimensional plane can be represented using two coordinates. In a regular tuple, these values would be accessed by index ([0] and [1]), but if we define a named tuple, Point, we can access them using x and y instead (although we can still use indexes, too, if we want):
Example:
from collections import namedtuple
# Regular tuple
p = (2, 4) # p[0] = 2, p[1] = 4
# Named tuple
Point = namedtuple('Point', 'x y')
q = Point(3, 5) # q.x = 3, q.y = 5
Example 2:
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y', 'z'], defaults = [1]);
a = Point(1, 1, 0); # a.x = 1, a.y = 1, a.z = 0
# Default value used for `z`
b = Point(2, 2); # b.x = 2, b.y = 2, b.z = 1 (default)
Share and Support
@Python_Codes7 090
Get all your investment related queries solved at one single place.
Tired of making loss in stock market ?🧐
Join this channel for highly accurate tips from experience traders !🦸
Services provided :
> Intraday calls in stocks and index
> Delivery calls for 10% in 15 days
> Stocks recommendation according to your needs.
Everything totally FREE as channel is PUBLICLY OPENED ! 🙋
JOIN : 📥
https://t.me/TechnicalTraderRAVI
7 090
Technical Trader RAVI
FREE BANKNIFTY CALLS
FREE DELIVERY CALLS ( stocks )
FREE SWING TRADING CALLS ( stocks )
FREE TIPS 1 PER DAY
Want more ?? Join our paid services to get more such calls ... Inbox me ...!
PURELY EDUCATIONAL PURPOSE
NOT SEBI REGISTERED
https://t.me/TechnicalTraderRAVI
7 090
merge
Python, List
Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions..👉🏻 Use max() combined with a list comprehension to get the length of the longest list in the arguments. .👉🏻 Use range() in combination with the max_length variable to loop as many times as there are elements in the longest list. .👉🏻If a list is shorter than max_length, use fill_value for the remaining items (defaults to None). .👉🏻zip() and itertools.zip_longest() provide similar functionality to this snippet. Code:
def merge(*args, fill_value = None):
max_length = max([len(lst) for lst in args])
result = []
for i in range(max_length):
result.append([
args[k][i] if i < len(args[k]) else fill_value for k in range(len(args))
])
return result
Example:
merge(['a', 'b'], [1, 2], [True, False])
Output: [['a', 1, True], ['b', 2, False]]
Share and Support
@Python_Codes7 090
🙏🏻 WELCOME 🙏🏻
TO
INDIA'S BIGGEST
ONLINE BETTING I'd AVAILABLE HERE👇 :
https://t.me/Bookiecircle_39
🤑 BOOKIECIRCLE 🤑
📈 BINARY (SHARE MARKET)
⚽ Scorrer
🏏 ALL Cricket
🎾 Tennis
🐴 Horse Racing
🐕 Grey Hound Racing
💰 SLOT GAME
🗣 Elections
🌈 IPL fancy
🎰 LIVE CASINO
♠️ TEEN PATTI
🔢 WARLI MARKET
Payment Mode Google Pay/Phone Pay/Paytm
5% Deposit Bonus each time
🔥24*7 Instant withdrawals 🔥
🔥within 5 minutes 🔥
Contact Number
Minimum Amount: 100💸
Maximum Amount : unlimited
⚽🏏🏸🥅🤼♀🤼♂🥋🏇🎰
https://t.me/Bookiecircle_39
7 090
What are named tuples in Python?
Python's named tuples are a very simple yet interesting feature that can make a developer's life easier. They are part of the collections module and act very similar to regular tuples, the main difference being that values stored in a named tuple can be accessed using field names instead of indexes.
For example, a point in the two-dimensional plane can be represented using two coordinates. In a regular tuple, these values would be accessed by index ([0] and [1]), but if we define a named tuple, Point, we can access them using x and y instead (although we can still use indexes, too, if we want):
Example:
from collections import namedtuple
# Regular tuple
p = (2, 4) # p[0] = 2, p[1] = 4
# Named tuple
Point = namedtuple('Point', 'x y')
q = Point(3, 5) # q.x = 3, q.y = 5
Apart from the increased readability of your code, named tuples provide a few other quality of life improvements. First and foremost, they allow for default values to be specified via the defaults iterable argument. Secondly, they have the ability to automatically rename duplicate or invalid fields via the rename boolean argument. And, finally, they even provide a convenient option to specify field names as a list or comma/space-separated string.
from collections import namedtuple
Point = namedtuple('Point', ['x', 'y', 'z'], defaults = [1]);
a = Point(1, 1, 0); # a.x = 1, a.y = 1, a.z = 0
# Default value used for
z
b = Point(2, 2); # b.x = 2, b.y = 2, b.z = 1 (default)
Where's the catch? you might ask. Well, it seems like there's none! The obvious parallel to dictionaries in terms of syntax doesn't seem to go any further, as named tuple instances do not have per-instance dictionaries, meaning they require as much memory as regular tuples.
Share and Support
@Python_Codes