Beiträge mit #PythonTip

#PythonTip

Öffentliche Beiträge auf X, die #PythonTip verwenden.

Verwandte Hashtags

  1. Daily Python Tip 🐍🐧@python_tip
    #pythontip from @raymondh: Another interesting use of #python's walrus operator is to compute differences between successive values in a data stream. >>> data = [10, 14, 34, 49, 70, 77] >>> prev = 0; [-prev + (prev := x) for x in data] [10, 4, 20, 15, 21, 7]
    52387
  2. Pluri@PluriLabs
    Learn to use 'try' and 'except' to handle errors in Python. Anticipating problems can make your code more robust. #PythonTip #coding
    11143
  3. Daily Python Tip 🐍🐧@python_tip
    You can name your slices: >>> record = "01234567890123456789I want this0123456789" >>> IWANT = slice(20,31) >>> record[IWANT] 'I want this' #python #pythontip
    12559
  4. Daily Python Tip 🐍🐧@python_tip
    #pythontip from @ratneshkush: If you want to use R in Python notebook, use rpy2 package: import rpy2 %load_ext rpy2.ipython # start each cell with %%R %%R a <- 'Ratnesh' b <- 'Data Science' print(paste(a,b)) # [1] Ratnesh Data Science
    0744
  5. Daily Python Tip 🐍🐧@python_tip
    #pythontip from @daviddelachurch Loving #Python3.5 PEP 448 for overwriting a dictionary of default values: >>> defaults = {"lenny": "white", "carl": "black"} >>> overwrite = {"lenny": "yellow"} >>> new = {**defaults, **overwrite} >>> new {'lenny': 'yellow', 'carl': 'black'}
    22485
  6. Harsh Mishra@harsh_casper
    #PythonTip: Use #Python #Generator to optimize your Memory Input. For reference, we load a CSV File where we pit a Normal Object, which loads the CSV by reading it versus a Generator Object, to compare their size. Here we can save a lot of memory just by using - generators.
    Herunterladen
    2116
  7. Mike Driscoll✓@driscollis
    🐍 #PythonTip: Use list comprehensions for concise and readable one-liners. Example: `[x**2 for x in range(10) if x%2 == 0]` #CodeClean
    64417.6K
  8. Daily Python Tip 🐍🐧@python_tip
    #pythontip by @bascodes: To avoid unintended consequences, change your function defaults arguments from (first figure) to (second figure). Otherwise, calling the function without that optional argument will access the same list each time.
    Herunterladen
    31563
  9. Ilya Schurov@ilyaschurov
    #PythonTip Допустим, у вас есть строчка y = f(x) + f(x)**2 Но вы не хотите считать f(x) дважды. Что делать? Заводить новую переменную? fx = f(x) y = fx + fx**2 Есть метод получше! y = (lambda t: t + t**2)(f(x))
    50131.2K
  10. pystar@pystar
    #PythonTip Use `itertools.count` to generate a range of floats pretty similar to how you can use `range(start, stop, step)` to generate a range of integers.
    Herunterladen
    3851
  11. Mehr Beiträge anzeigen