TopTgm
simple-python-programming

Simple Python | Programming

Locale: en
Subscribers:51
Category: technology
Description:
We share useful tips, code examples, problem solutions, and news from the Python world.
?The get() method on Python dicts and its "default" arg

# The get() method on dicts
# and its "default" argument

name_for_userid = {
382: "Alice",
590: "Bob",
951: "Dilbert",
}

def greeting(userid):
return "Hi %s!" % name_for_userid.get(userid, "there")

>>> greeting(382)
"Hi Alice!"

>>> greeting(333333)
"Hi there!"


When "get()" is called it checks if the given key exists in the dict.

If it does exist, the value for that key is returned.

If it does not exist then the value of the default argument is returned instead.
4/23/2024, 11:04:25 AM
?Context menu: a python library to create and deploy cross-platform native context menus.

A python library to develop and deploy custom context menus.

▪️
4/23/2024, 9:51:34 AM
With f-strings you can use the = modifier for including the code of the variable interpolation:
>>> a = 1.6
>>> print(f'We have {a=} and {int(a)=}.')
>>> We have a=1.6 and int(a)=1.


You can use classes to define decorators instead of functions:
>>> class show_time:
... def __init__(self, func):
... self.func = func
... def __call__(self, *args, **kwargs):
... start = time()
... result = self.func(*args, **kwargs)
... print(f'It took {time() - start:.4f}s')
... return result
...
>>> @show_time
... def test():
... return sum(n**2 for n in range(1000000))
...
>>> test()
It took 0.1054s
333332833333500000


The mode attribute for open is 'r' by default:
>>> with open('test.txt') as f:
... print(f.read())
>>> It works!
4/22/2024, 9:09:47 AM
My latest TILs about Python

After so long, I still find basic stuff in Python that I didn't know about. Here are some of my most recent TILs.

You can use underscores to separate digits in a number and they'll be ignored by the interpreter:
>>> 1000000  # confusing
1000000
>>> 1e6 # not confusing but creates a float
1000000.0
>>> 1_000_000 # great!
1000000


The sum method accepts a second parameter that is the initial value of the sum:
>>> base = 20
>>> sum([1, 2, 3], base)
26
4/22/2024, 2:59:47 AM
?How to sort a Python dict by value

# How to sort a Python dict by value
# (== get a representation sorted by value)

>>> xs = {'a': 4, 'b': 3, 'c': 2, 'd': 1}

>>> sorted(xs.items(), key=lambda x: x[1])
[('d', 1), ('c', 2), ('b', 3), ('a', 4)]

# Or:

>>> import operator
>>> sorted(xs.items(), key=operator.itemgetter(1))
[('d', 1), ('c', 2), ('b', 3), ('a', 4)]
4/20/2024, 1:23:56 PM
??As part of the project's continued development, the Desbordante team has posted new Python script examples on GitHub. "As the project is currently under-documented, we hope these will be useful for our potential users. . To improve the overall level of documentation, we have also published a few tutorials - see the tutorials section," the developers clarified.
4/20/2024, 8:05:24 AM
? Desbordante data profiler 2.0.0 release

?On April 16, 2024, the second major release of , which allows you to search for various primitives in tables, took place. The source code of the project is under the GNU Affero General Public License v3.0. The first stable version of Desbordante was released in December 2023.

?Desbordante can perform two categories of tasks: searching for different primitives, and performing some work using primitive search algorithms. The core of Desbordante is a console application that has an extremely simple usage scenario: a csv table is fed as input, the primitive to be searched, such as a functional dependency, an algorithm and optionally parameters, is specified, and the output is a set of found dependencies. In addition, all Desbordante components are containerized.
4/20/2024, 8:05:10 AM
?Different ways to test multiple flags at once in Python

# Different ways to test multiple
# flags at once in Python
x, y, z = 0, 1, 0

if x == 1 or y == 1 or z == 1:
print('passed')

if 1 in (x, y, z):
print('passed')

# These only test for truthiness:
if x or y or z:
print('passed')

if any((x, y, z)):
print('passed')
4/19/2024, 3:41:31 AM
Automate the Boring Stuff with Python - Practical Programming for Total Beginners by Al Sweigart is "written for office workers, students, administrators, and anyone who uses a computer to learn how to code small, practical programs to automate tasks on their computer."
|| || ||
4/18/2024, 4:04:15 AM
How to use uv: A superfast Python package installer

Crafted by the Astral team, the creators behind the renowned Ruff Python linting tool, UV sets out to revolutionize Python project management. It aspires to consolidate various command-line tools like pip and venv into a single, comprehensive solution. What sets UV apart is its foundation in Rust, a choice made to enhance its performance significantly compared to its counterparts, possibly achieving speeds beyond comparison.

Read the manual
4/16/2024, 10:53:21 AM

Related Groups

Nomota Al
Nomota Al
technology2.41K

In the fusion of technology and creativity, limitless innovation blossoms.Portal: https://t.me/NomotaAlMIGRATION IS LIVE NOMOTA AI V2remember to migrate your old token via our dApp below1. scroll down and select migrate 2. connect wallet and confirm signature request button that pop up3. this will move your token from the old contract to the new contract address4. once signature request is confirmed successfully refresh wallet your V2 token will be there

AlgoTech (ALGT)
AlgoTech (ALGT)
technology12.39K

A decentralized algorithmic crypto trading platform to revolutionize trading and investment with innovative technologies and automation??STAGE 3 Extension??Hello Everyone,We're delighted to share some exciting news with you!????First and foremost, we're pleased to announce that all dividends have been successfully released and paid to all investors in levels 1-8! This is just a taste of what's to come – moving forward, you can expect a dividend once per month from the profits generated by our algorithms through our AUM. We hope this news brings a smile to your face!????But wait, there's more! We've got another major update to share. We've recently sold off our entire Stage 4 token supply to an institutional client (family office). While they initially expressed interest in purchasing the entire supply during presale, they've settled for Stage 4 instead. Due to this exciting development and the numerous requests we've received, we've made the decision to extend the presale until Stage 3 sells out.??Currently, there are only around 30,000,000 ALGT tokens left in Stage 3. Instead of burning these tokens, we're offering you the incredible opportunity to purchase them at $0.08 each before we release the token on DEX for $0.15. This is your chance to get in early and secure your investment at a discounted rate!????We truly hope you appreciate these decisions as much as we do, and we're counting on your support to help us sell out this stage as soon as possible.????In addition to these developments, I am pleased to announce that the initial token airdrop is scheduled to occur within the next 10 days. This milestone represents the commencement of token distribution, a pivotal moment in our journey together.????We are deeply encouraged by these advancements and remain steadfast in our commitment to delivering value to our investors. Your continued support is paramount as we navigate this transformative phase.????Thank you for your confidence in our vision.Let's make this happen together!

AmpereChain - Connect the World
AmpereChain - Connect the World
technology7.35K

AmpereChain: The fastest D-QBFT blockchain with AMPERE crypto. Pioneering EVM public chain with privacy nodes. Unmatched speed, efficiency, privacy, and TPS. #DecentralizedTechDear Community,I have received lot of DM regarding vesting time of migration.Considering queries and objection we have decided to go with voting for merging decision1. Project is registered and they have shared formation, approval certificate2. There is one way(Either go with them or reject them). Once we opt for rejection we are completely out3. Our community must have to understand they are yet in presale and asking all tokens to release without reaching certain market cap will crash project. I had discussion with him for early release and he highlighted it. Many of you have intention to exit but none of project owner will allow such crash4. I asked same questions to seed funding users few days back and they opted to stay with them5. Dom and Moh already left project with no backing to support itI have clearly mentioned positive as well as negative side with our current situation.Requesting everyone to vote for next 3 days which will help us to go forward or return back to previous steps leaving them.

Kima Network
Kima Network
technology96.25K

The Decentralized Money Transfer Protocol Revolutionizing Financial Interoperability. Incubated by @ChainGPT Announcements: t.me/KimaNetworkNews? HackaTRON Season 6 Twitter Space is LIVE TODAY! ?We're thrilled to announce that Kima is joining today's Twitter Space hosted by TRON DAO. ?As a proud Platinum Sponsor of HackaTRON Season 6, we're excited to dive into discussions on emerging blockchain technologies, the latest in the Bitcoin and crypto ecosystems, and share insights into the innovative solutions alongside esteemed projects:✅Chain GPT✅AI Tech✅GT-Protocol✅Router Protocol✅Moby Media⭐️ Highlight: Our CMO, Tomer Warschauer Nuni, will be speaking at the Bitcoin Halving celebration, showcasing how Kima is shaping the future of blockchain technology.

METABLAZE - OFFICIAL COMMUNITY
METABLAZE - OFFICIAL COMMUNITY
technology5.97K

We transform Blockchain and AI technology into immersive entertainment experiences through gaming, storytelling & digital assets. MetaBlaze is where the story becomes the ecosystem.Dear MetaBlazers,It's with a heavy heart to announce that MetaBlaze failed to reach it's fundraising goal by a long shot. This means that MetaBlaze is financially incapable of proceeding to third-party launchpad sales and token launch.All community members who made purchases between February 14th to February 28th, 2024, have been fully refunded. Confirmation emails are on their way.The team is acutely aware of the disappointment and frustration resonating throughout the community. We're heartbroken to have reached this point and share in the colossal disappointment; we feel the utmost sorrow for letting our community down. Most team members can no longer continue working without compensation and must seek new job opportunities. Without them, daily operations are no longer feasible.MetaBlaze's present failure is not necessarily permanent and a couple team members will continue pursuing other viable options, such as possibly passing the torch to an entirely new team or securing funding through other means. We are actively and pursuing these potential opportunities.We acknowledge the damage to the current team's reputation and credibility. Nevertheless, we remain optimistic about MetaBlaze's prospects and are confident that placing the company in the hands of a new team could revitalize both the organization and its community. In the event of such a transition, several team members are dedicated to providing support to facilitate the new team's integration.Any concrete updates regarding these developments will be shared in the group once they are fully confirmed and official.While we thank you for the support, we are very sorry for letting you down. Remain hopeful, all hope is not lost

Memeinator | Official Telegram
Memeinator | Official Telegram
technology31.47K

Forged from the depths of meme culture: a fusion of advanced technology, cutting-edgeAI mastery & a cold ruthless meme-targeting system - the Memeinator has emerged asthe game-changer and leader of the resistance.WITHIN THE EXPANSE OF THE DIGITAL REALM, WHERE MEMES PROLIFERATE, A BRAVE CHAMPION ARISES WITH A GRAND OBJECTIVE: TO REVOLUTIONIZE OUR VIRTUAL LANDSCAPE. ?✨WELCOME THE MEMEINATOR - SENTINEL OF UNFILTERED HUMOR, UNDERTAKING A NOBLE QUEST TO ELIMINATE MEDIOCRITY'S GRIP. ?? DETERMINED TO REVOLUTIONIZE YOUR MEME GAME? ?INTRODUCING MEMESCANNER: YOUR MEME MASTER! ?OBLITERATE LOW-QUALITY MEMES WITH PRECISION TECH! ?

This website is not affiliated with Telegram. Visual content shown here might be copyrighted by rightful owners. No infringement intended.
DISCLAIMER: Infos without tag OFFICIAL posted on website are public, and wo are not responsible for the content on their media. Join or subscribe the info there maybe some risk with you. If you have any issueContact UsPlease!