Python_Labs🐍
591 subscribers
267 photos
11 videos
28 files
204 links
Download Telegram
The get() method on Python dicts and its "default" arg

#pytrick
Python_Labs🐍
The get() method on Python dicts and its "default" arg #pytrick
The get() method on Python dicts and its "default" arg
وقتی متد get را روی یک دیکشنری فراخوانی میکنید بررسی میکند که این کلید در دیکشنری موجود است یا خیر. اگر موجود بود مقدارش را برمیگرداند، در غیر این صورت مقدار پیش فرضی که برایش مشخص کرده اید برمیگردد.



# 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!"
Forwarded from Tensorflow(@CVision) (Alireza Akhavan)
با سلام
گارگاه "اصول شبکه های عصبی عمیق در بینایی ماشین مقدماتی" در تاریخ های زیر برگزار می گردد. علاقه مندان می توانند از طریق لینک زیر ثبت نام کنند.

جلسه اول: چهارشنبه مورخ 23 آبان ماه ساعت 1 الی 5
جلسه دوم: چهارشنبه مورخ 30 آبان ماه ساعت 1 الی 5


پوستر و اطلاعات بیشتر:

https://t.iss.one/cvision/736
لینک ثبت نام:
https://plan.azad.ac.ir/fa/page/9755
Python's namedtuples can be a great alternative to defining a class manually
#pytrick
You can use "json.dumps()" to pretty-print Python dicts
... (as an alternative to the "pprint" module)
#pytrick
بی نهایت در پایتون
پایتون مثبت و منفی بی نهایت واقعی داره! مثلا عددی که هیچ عددی ازش کوچکتر نیست، بدون محدودیت تعداد ارقام!
Python_Labs🐍
بی نهایت در پایتون پایتون مثبت و منفی بی نهایت واقعی داره! مثلا عددی که هیچ عددی ازش کوچکتر نیست، بدون محدودیت تعداد ارقام!
#سوال
تو مثال بالا، به نظرتون خروجی کد زیر True است یا False ؟

negative_inf < negative_inf +1

آیا واقع مثل منفی بی نهایت در ریاضی رفتار میکنه و False بر میگردونه!؟
تو پایتون میتونید از کلاس های پایه ارث برده و متناسب نیازتون override کنید.

How to inherit and extend a list object in Python? (Stackoverflow)
پایتون زبان برنامه نویسی رسمی برای آموزش در فرانسه خواهد شد.

https://twitter.com/nnja/status/1062621193696612352
ممکنه برخورده باشید بعضی مواقع متغیر رشته ای به این صورت است!

b'salam'

Why the 'b's in front of the string? Bytes literals are always prefixed with 'b' or 'B'; they produce an instance of the bytes type instead of the str type. They may only contain ASCII characters; bytes with a numeric value of 128 or greater must be expressed with escapes.

https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal
"is" vs "=="
#pytrick
functools — Higher-order functions and operations on callable objects

partial gives default values to the parameters of a function that would otherwise not have default values.
#pytrick
How to count the occurrence of certain item in an ndarray in Python?

فرض کنید در یک وکتور نامپای منحصر به فردها و تعداشان را میخواهید بدانید...
مناسب برای گرفتم آمار لیبل های دیتاست .

a = numpy.array([0, 3, 0, 1, 0, 1, 2, 1, 0, 0, 0, 0, 1, 3, 4])
unique, counts = numpy.unique(a, return_counts=True)
dict(zip(unique, counts))


{0: 7, 1: 4, 2: 1, 3: 2, 4: 1}
Functions are first-class citizens in Python
#pytrick
Dicts can be used to emulate switch/case statements

#pytrick
سلام.
از دوستانی که کلاس آزمایشگاه متلب داشتند و پایتون ارائه دادم؛ ممنون میشم پاسخ سوال زیر را برایم در خصوصی ارسال کنند. @alirezaweb

یکی از اساتید دیگر دانشگاه به گفته دانشگاه قصد دارد در کارگاه متلب، پایتون ارائه کند.
چه مباحثی از کلاس در چه درسهایی به کارتان آمده و چه مباحثی نیاز بود بیان شود و بیان نشده است؟
Forwarded from Tensorflow(@CVision) (Alireza Akhavan)
#خبر
نامپای روی GPU با قابلیت autodiff و اضافه شدن JIT کامپایلر ...
(Pic: https://t.iss.one/cvision/813 )
JAX is NumPy on the CPU and GPU with autodiff and JIT compilation. It's just been released, try it out!

https://github.com/google/jax

همین الان روی گوگل کولب شروع کنید:
https://colab.research.google.com/github/google/jax/blob/master/notebooks/quickstart.ipynb
Python's list comprehensions are awesome

even_squares = [x * x for x in range(10) if not x % 2]

#pytrick