IT |
気になる、記になる… |
TwitterのAndroid版、ようやくツイートのテキストが選択可能になる模様 |
https://taisy0.com/2022/04/03/155404.html
|
twitter |
2022-04-02 16:16:13 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
【初心者が始める】githubの環境構築(後編) |
https://qiita.com/Ricky12-7/items/ce4663bfe18a880713ba
|
そのAccesstokenを先ほどの手順のパスワードの代わりに打ち込めば、承認がされます。 |
2022-04-03 01:33:39 |
python |
Pythonタグが付けられた新着投稿 - Qiita |
【緑を目指す灰・茶必見】Atcoder ABC246 C・D問題 Python3解説 |
https://qiita.com/chanhina/items/ec775a271242f4e3e9cc
|
コードCpynkxmapintinputsplitAlistmapintinputsplit商品を高いもん順にソートAsortreverseTruecntクーポンを使った枚数ans答え出力foriinrangencntAixクーポンを使った枚数ifcntgtk場合分け①途中でクーポンが無くなる場合で、クーポンがなくなる時の商品の値段AiAikcntAixxcntkクーポンはk枚以上使えないbreakAiAix値引き後の値段に置き換え場合分け①途中でクーポンが無くなる場合ifcntkanssumA場合分け②いくつかの商品のみが円になる場合elifcntltkandkcntltnAsortreverseTrue値引き後の値段が高いもん順にソートanssumAkcntクーポンが無くなった時点で、残った商品の値引き後の価格の和場合分け③全て円になる場合elseansprintansD問題『variableFunction』問題ページD問題variableFunctionむずい、むずいよぉ、ウワァァァァァァヽД´ノァァァァァァン考え方Nはの乗だけど、Xは次式なので、abはに収まることに気づくのがポイント。 |
2022-04-03 01:19:57 |
Linux |
Ubuntuタグが付けられた新着投稿 - Qiita |
Ubuntu 22.04 Jammy Jellyfishのibus-mozcで変換候補が左下に出てしまう場合の対策 |
https://qiita.com/relu/items/114836c774848b1ce7da
|
etcenvironment |
2022-04-03 01:17:52 |
海外TECH |
MakeUseOf |
How Electrify America’s Future Charging Stations Will Improve Your EV Charging Experience |
https://www.makeuseof.com/how-electrify-america-improve-ev-charging-experience/
|
How Electrify America s Future Charging Stations Will Improve Your EV Charging ExperienceElectrify America will soon provide an EV charging experience you ve never seen before Here s everything you need to know |
2022-04-02 16:15:15 |
海外TECH |
MakeUseOf |
How to Fix the Battle.net BLZBNTAGT00000BB8 Error in Windows 11 and 10 |
https://www.makeuseof.com/windows-11-10-battle-net-blzbntagt00000bb8-error/
|
How to Fix the Battle net BLZBNTAGTBB Error in Windows and The mysterious BLZBNTAGTBB error can hamper your gaming on Battle net but there are fixes you can perform on Windows to get rid of it |
2022-04-02 16:15:14 |
海外TECH |
DEV Community |
Amazing Functools Features in Python |
https://dev.to/vivekthedev/amazing-functools-features-in-python-3gnc
|
Amazing Functools Features in PythonI was recently reading Django s Source Code and I came across the wraps decorator which led me to the functools docs where I discovered some fantastic functools features That discovery led to the creation of this article This tutorial will teach you how to use some fantastic functools methods to make your life simpler What is functoolsfunctools is a Python built in module that contains Higher Order functions that can interact with other functions A complete functools documentation may be found here Let s see some decorators in action lru cacheWhen invoking a function with the same arguments this decorator in the functools module saves n number of function calls in cache which saves a lot of time Assume for the sake of demonstration that we have a very large function that takes a long time to execute The function a heavy operation takes seconds to execute in this example import timestart time time def a heavy operation time sleep return print a heavy operation print a heavy operation print time time start Output It takes about seconds to run the above code To the above function we ll add lru cache import timefrom functools import lru cachestart time time lru cache def a heavy operation time sleep return print a heavy operation print a heavy operation print time time start Output Take a look at how using lru cache made our code run faster Python saved the function s cache and retrieved the cached value reducing our execution time wrapsWraps is used in functools to keep the function details When we decorate a function the function s information is gone We utilise the wraps decorator on the decorator wrapper function to prevent this Take a look at this code to see what I mean from functools import lru cachedef my decorator func def log args kwargs print Running return func args kwargs return log my decoratordef add a b my beautiful doc return a bRun the above code in i mode using python i file pyLet s see what we have gt gt gt add Running gt gt gt add Running gt gt gt add name log gt gt gt add doc gt gt gt We can see that our decorator is operating properly in the previous example since it is consistently “Running on each run However our function s information has been lost and it is unable to return the name or the docstring We have wraps to help us with this problem Make the changes below to the code from functools import wrapsdef my decorator func wraps func def log args kwargs print Running return func args kwargs return log my decoratordef add a b my beautiful doc return a bNow again run the code using python i file py gt gt gt add Running gt gt gt add name add gt gt gt add doc my beautiful doc gt gt gt Voila The function information is now saved in our function singledispatchTo create a generic function singledispatch is utilised Generic functions are those that perform the same operation on a variety of data types Assume I want to create a function that returns the first value from an iterable of several data types def return first element data if isinstance data list print data elif isinstance data str print data split elif isinstance data dict print list data values else print print data Now run python i file py to run the code in interactive mode gt gt gt return first element Age Height gt gt gt return first element Hello Mr Python Hello gt gt gt return first element gt gt gt Our function is effective but it isn t clean Using if elif else statements to create generic functions is not recommended in Python So what s the solution singledispatch of course Let s make a few modifications to our code from functools import singledispatch singledispatchdef return first el data return data return first el register list def data return data return first el register dict def data return list data values return first el register str def data return data split To check the results run the code again in interactive mode with python i file py gt gt gt return first el Age Height gt gt gt return first el Hello Mr Python Hello gt gt gt return first el gt gt gt return first el Look how our return first el function acted as a fallback function when no data type matched for set Look at how much cleaner our code is now the singledispatch made it easier to add more data types and each datatype now gets its own place where we can perform further operations on the data total orderingThe total ordering decorator saves a ton of time in Object Oriented Progrmming Consider this example the below class declares a class Man with name and age property and eq and lt lt dunder methods class Man def init self name age self name name self age age def eq self o return self age o age def lt self o return self age lt o ageLet s try to run the code to see what we have gt gt gt obj Man Vivek gt gt gt obj Man Alex gt gt gt obj obj gt gt gt obj objFalse gt gt gt obj lt objTrue gt gt gt obj gt objTraceback most recent call last File lt stdin gt line in lt module gt TypeError gt not supported between instances of Man and Man Our code worked for and lt but it didn t work when we used an operator that wasn t defined in the class Given that we create at least one operator dunder method and eq method total ordering generates the gt gt and more comparison operators for our class Let s add our decorator just above the class from functools import total ordering total orderingclass Man Now again run thee code in interactive mode to see the results gt gt gt o Man Vivek gt gt gt b Man Alex gt gt gt o bFalse gt gt gt o gt b False gt gt gt o lt bTrueTake a look at how total ordering generated our class s comparison operators ConclusionI hope you found this post useful I strongly advise you to study the documentation in order to fully comprehend the internal mechanics of these higher level functions If you enjoyed this please consider following me on Twitter where I share stuff related to Python Web development and open source software I ll see you there |
2022-04-02 16:35:57 |
海外科学 |
NYT > Science |
Astronomers and Space Enthusiasts on Their Favorite Exoplanets |
https://www.nytimes.com/2022/04/02/science/nasa-exoplanets-5000.html
|
Astronomers and Space Enthusiasts on Their Favorite ExoplanetsNASA recently announced that it had detected more than exoplanets so we asked astronomers actors and an astronaut to share their favorite worlds orbiting distant stars |
2022-04-02 16:21:46 |
海外科学 |
NYT > Science |
Is Russia Quitting the International Space Station? Not Quite. |
https://www.nytimes.com/2022/04/02/world/europe/russia-space-station.html
|
partnership |
2022-04-02 16:13:56 |
ニュース |
BBC News - Home |
Manchester Airport: More delays blamed on lack of staff |
https://www.bbc.co.uk/news/uk-60968488?at_medium=RSS&at_campaign=KARANGA
|
baggage |
2022-04-02 16:18:28 |
ニュース |
BBC News - Home |
Plane crashes into block of flats near Bicester |
https://www.bbc.co.uk/news/uk-england-oxfordshire-60967351?at_medium=RSS&at_campaign=KARANGA
|
aircraft |
2022-04-02 16:01:18 |
ニュース |
BBC News - Home |
Chelsea 1-4 Brentford: Christian Eriksen scores first Bees goal in comeback win |
https://www.bbc.co.uk/sport/football/60883946?at_medium=RSS&at_campaign=KARANGA
|
bridge |
2022-04-02 16:28:58 |
ニュース |
BBC News - Home |
Burnley 0-2 Man City: Kevin de Bruyne & Ilkay Gundogan secure win |
https://www.bbc.co.uk/sport/football/60883950?at_medium=RSS&at_campaign=KARANGA
|
burnley |
2022-04-02 16:31:21 |
北海道 |
北海道新聞 |
愛知で住宅火災、4人搬送 90代女性と連絡取れず |
https://www.hokkaido-np.co.jp/article/664795/
|
愛知県碧南市上町 |
2022-04-03 01:07:00 |
コメント
コメントを投稿