kandi background
Explore Kits

pattern | Web mining module for Python with tools for scraping | Natural Language Processing library

 by   clips Python Version: Current License: BSD-3-Clause

 by   clips Python Version: Current License: BSD-3-Clause

Download this library from

kandi X-RAY | pattern Summary

pattern is a Python library typically used in Institutions, Learning, Education, Artificial Intelligence, Natural Language Processing applications. pattern has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
[![Build Status](http://img.shields.io/travis/clips/pattern/master.svg?style=flat)](https://travis-ci.org/clips/pattern/branches) [![Coverage](https://img.shields.io/coveralls/clips/pattern/master.svg?style=flat)](https://coveralls.io/github/clips/pattern?branch=master) [![PyPi version](http://img.shields.io/pypi/v/pattern.svg?style=flat)](https://pypi.python.org/pypi/pattern) [![License](https://img.shields.io/badge/License-BSD%203—​Clause-green.svg?style=flat)](https://github.com/clips/pattern/blob/master/LICENSE.txt).
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • pattern has a medium active ecosystem.
  • It has 7951 star(s) with 1559 fork(s). There are 564 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 119 open issues and 75 have been closed. On average issues are closed in 387 days. There are 45 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of pattern is current.
pattern Support
Best in #Natural Language Processing
Average in #Natural Language Processing
pattern Support
Best in #Natural Language Processing
Average in #Natural Language Processing

quality kandi Quality

  • pattern has 0 bugs and 0 code smells.
pattern Quality
Best in #Natural Language Processing
Average in #Natural Language Processing
pattern Quality
Best in #Natural Language Processing
Average in #Natural Language Processing

securitySecurity

  • pattern has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • pattern code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
pattern Security
Best in #Natural Language Processing
Average in #Natural Language Processing
pattern Security
Best in #Natural Language Processing
Average in #Natural Language Processing

license License

  • pattern is licensed under the BSD-3-Clause License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
pattern License
Best in #Natural Language Processing
Average in #Natural Language Processing
pattern License
Best in #Natural Language Processing
Average in #Natural Language Processing

buildReuse

  • pattern releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • pattern saves you 46809 person hours of effort in developing the same functionality from scratch.
  • It has 54830 lines of code, 2745 functions and 169 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
pattern Reuse
Best in #Natural Language Processing
Average in #Natural Language Processing
pattern Reuse
Best in #Natural Language Processing
Average in #Natural Language Processing
Top functions reviewed by kandi - BETA

kandi has reviewed pattern and discovered the below as its top functions. This is intended to give you an instant insight into pattern implemented functionality, and help decide if they suit your requirements.

  • Returns a list of possible assessments .
    • Find keywords in a string .
      • Predict using SVM .
        • Train the model .
          • Search for Facebook .
            • Check if the word matches the constraints .
              • Find the tokens in a string .
                • Parse options .
                  • Initialize a dictionary .
                    • Return javascript representation .

                      Get all kandi verified functions for this library.

                      Get all kandi verified functions for this library.

                      pattern Key Features

                      Web mining module for Python, with tools for scraping, natural language processing, machine learning, network analysis and visualization.

                      Example

                      copy iconCopydownload iconDownload
                      from pattern.web import Twitter
                      from pattern.en import tag
                      from pattern.vector import KNN, count
                      
                      twitter, knn = Twitter(), KNN()
                      
                      for i in range(1, 3):
                          for tweet in twitter.search('#win OR #fail', start=i, count=100):
                              s = tweet.text.lower()
                              p = '#win' in s and 'WIN' or 'FAIL'
                              v = tag(s)
                              v = [word for word, pos in v if pos == 'JJ'] # JJ = adjective
                              v = count(v) # {'sweet': 1}
                              if v:
                                  knn.train(v, type=p)
                      
                      print(knn.classify('sweet potato burger'))
                      print(knn.classify('stupid autocorrect'))

                      Installation

                      copy iconCopydownload iconDownload
                      cd pattern-3.6
                      python setup.py install

                      Repeatedly removing the maximum average subarray

                      copy iconCopydownload iconDownload
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def upperSumHullLengths(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      
                      print(upperSumHullLengths([  1,   7,   8,   4,   2,   1,   4]))
                      
                      [3, 1, 3]
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def upperSumHullLengths(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      
                      print(upperSumHullLengths([  1,   7,   8,   4,   2,   1,   4]))
                      
                      [3, 1, 3]
                      
                      from itertools import accumulate, pairwise
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                        min   median   mean     max  
                       65 ms  164 ms  159 ms  249 ms  kc
                       38 ms   98 ms   92 ms  146 ms  kc_Pychoed_1
                       58 ms  127 ms  120 ms  189 ms  kc_Pychoed_2
                      134 ms  137 ms  138 ms  157 ms  Matt
                      101 ms  102 ms  103 ms  111 ms  Matt_Pychoed
                      
                        min   median   mean     max  
                      102 ms  106 ms  107 ms  116 ms  kc
                       60 ms   61 ms   61 ms   62 ms  kc_Pychoed_1
                       76 ms   77 ms   77 ms   86 ms  kc_Pychoed_2
                        0 ms    1 ms    1 ms    1 ms  Matt
                        0 ms    0 ms    0 ms    0 ms  Matt_Pychoed
                      
                      from timeit import default_timer as timer
                      from statistics import mean, median
                      import random
                      from typing import List, Tuple
                      import math
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0.0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if (new_average >= best_average
                                      or math.isclose(new_average, best_average)):
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_1(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if new_average >= best_average:
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def Matt(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      def pairwise(lst):
                          return zip(lst, lst[1:])
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      funcs = kc, kc_Pychoed_1, kc_Pychoed_2, Matt, Matt_Pychoed
                      stats = min, median, mean, max
                      tss = [[] for _ in funcs]
                      for r in range(1, 21):
                          print(f'After round {r}:')
                          arr = random.choices(range(1, 1001), k=100_000)
                          # arr = list(range(1000, 1, -1))
                          expect = None
                          print(*(f'{stat.__name__:^7}' for stat in stats))
                          for func, ts in zip(funcs, tss):
                              t0 = timer()
                              result = func(arr)
                              t1 = timer()
                              ts.append(t1 - t0)
                              if expect is None:
                                  expect = result
                              assert result == expect
                              print(*('%3d ms ' % (stat(ts) * 1e3) for stat in stats), func.__name__)
                          print()
                      
                      from itertools import accumulate, pairwise
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                        min   median   mean     max  
                       65 ms  164 ms  159 ms  249 ms  kc
                       38 ms   98 ms   92 ms  146 ms  kc_Pychoed_1
                       58 ms  127 ms  120 ms  189 ms  kc_Pychoed_2
                      134 ms  137 ms  138 ms  157 ms  Matt
                      101 ms  102 ms  103 ms  111 ms  Matt_Pychoed
                      
                        min   median   mean     max  
                      102 ms  106 ms  107 ms  116 ms  kc
                       60 ms   61 ms   61 ms   62 ms  kc_Pychoed_1
                       76 ms   77 ms   77 ms   86 ms  kc_Pychoed_2
                        0 ms    1 ms    1 ms    1 ms  Matt
                        0 ms    0 ms    0 ms    0 ms  Matt_Pychoed
                      
                      from timeit import default_timer as timer
                      from statistics import mean, median
                      import random
                      from typing import List, Tuple
                      import math
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0.0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if (new_average >= best_average
                                      or math.isclose(new_average, best_average)):
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_1(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if new_average >= best_average:
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def Matt(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      def pairwise(lst):
                          return zip(lst, lst[1:])
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      funcs = kc, kc_Pychoed_1, kc_Pychoed_2, Matt, Matt_Pychoed
                      stats = min, median, mean, max
                      tss = [[] for _ in funcs]
                      for r in range(1, 21):
                          print(f'After round {r}:')
                          arr = random.choices(range(1, 1001), k=100_000)
                          # arr = list(range(1000, 1, -1))
                          expect = None
                          print(*(f'{stat.__name__:^7}' for stat in stats))
                          for func, ts in zip(funcs, tss):
                              t0 = timer()
                              result = func(arr)
                              t1 = timer()
                              ts.append(t1 - t0)
                              if expect is None:
                                  expect = result
                              assert result == expect
                              print(*('%3d ms ' % (stat(ts) * 1e3) for stat in stats), func.__name__)
                          print()
                      
                      from itertools import accumulate, pairwise
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                        min   median   mean     max  
                       65 ms  164 ms  159 ms  249 ms  kc
                       38 ms   98 ms   92 ms  146 ms  kc_Pychoed_1
                       58 ms  127 ms  120 ms  189 ms  kc_Pychoed_2
                      134 ms  137 ms  138 ms  157 ms  Matt
                      101 ms  102 ms  103 ms  111 ms  Matt_Pychoed
                      
                        min   median   mean     max  
                      102 ms  106 ms  107 ms  116 ms  kc
                       60 ms   61 ms   61 ms   62 ms  kc_Pychoed_1
                       76 ms   77 ms   77 ms   86 ms  kc_Pychoed_2
                        0 ms    1 ms    1 ms    1 ms  Matt
                        0 ms    0 ms    0 ms    0 ms  Matt_Pychoed
                      
                      from timeit import default_timer as timer
                      from statistics import mean, median
                      import random
                      from typing import List, Tuple
                      import math
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0.0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if (new_average >= best_average
                                      or math.isclose(new_average, best_average)):
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_1(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if new_average >= best_average:
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def Matt(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      def pairwise(lst):
                          return zip(lst, lst[1:])
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      funcs = kc, kc_Pychoed_1, kc_Pychoed_2, Matt, Matt_Pychoed
                      stats = min, median, mean, max
                      tss = [[] for _ in funcs]
                      for r in range(1, 21):
                          print(f'After round {r}:')
                          arr = random.choices(range(1, 1001), k=100_000)
                          # arr = list(range(1000, 1, -1))
                          expect = None
                          print(*(f'{stat.__name__:^7}' for stat in stats))
                          for func, ts in zip(funcs, tss):
                              t0 = timer()
                              result = func(arr)
                              t1 = timer()
                              ts.append(t1 - t0)
                              if expect is None:
                                  expect = result
                              assert result == expect
                              print(*('%3d ms ' % (stat(ts) * 1e3) for stat in stats), func.__name__)
                          print()
                      
                      from itertools import accumulate, pairwise
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                        min   median   mean     max  
                       65 ms  164 ms  159 ms  249 ms  kc
                       38 ms   98 ms   92 ms  146 ms  kc_Pychoed_1
                       58 ms  127 ms  120 ms  189 ms  kc_Pychoed_2
                      134 ms  137 ms  138 ms  157 ms  Matt
                      101 ms  102 ms  103 ms  111 ms  Matt_Pychoed
                      
                        min   median   mean     max  
                      102 ms  106 ms  107 ms  116 ms  kc
                       60 ms   61 ms   61 ms   62 ms  kc_Pychoed_1
                       76 ms   77 ms   77 ms   86 ms  kc_Pychoed_2
                        0 ms    1 ms    1 ms    1 ms  Matt
                        0 ms    0 ms    0 ms    0 ms  Matt_Pychoed
                      
                      from timeit import default_timer as timer
                      from statistics import mean, median
                      import random
                      from typing import List, Tuple
                      import math
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0.0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if (new_average >= best_average
                                      or math.isclose(new_average, best_average)):
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_1(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if new_average >= best_average:
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def Matt(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      def pairwise(lst):
                          return zip(lst, lst[1:])
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      funcs = kc, kc_Pychoed_1, kc_Pychoed_2, Matt, Matt_Pychoed
                      stats = min, median, mean, max
                      tss = [[] for _ in funcs]
                      for r in range(1, 21):
                          print(f'After round {r}:')
                          arr = random.choices(range(1, 1001), k=100_000)
                          # arr = list(range(1000, 1, -1))
                          expect = None
                          print(*(f'{stat.__name__:^7}' for stat in stats))
                          for func, ts in zip(funcs, tss):
                              t0 = timer()
                              result = func(arr)
                              t1 = timer()
                              ts.append(t1 - t0)
                              if expect is None:
                                  expect = result
                              assert result == expect
                              print(*('%3d ms ' % (stat(ts) * 1e3) for stat in stats), func.__name__)
                          print()
                      
                      from itertools import accumulate, pairwise
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                        min   median   mean     max  
                       65 ms  164 ms  159 ms  249 ms  kc
                       38 ms   98 ms   92 ms  146 ms  kc_Pychoed_1
                       58 ms  127 ms  120 ms  189 ms  kc_Pychoed_2
                      134 ms  137 ms  138 ms  157 ms  Matt
                      101 ms  102 ms  103 ms  111 ms  Matt_Pychoed
                      
                        min   median   mean     max  
                      102 ms  106 ms  107 ms  116 ms  kc
                       60 ms   61 ms   61 ms   62 ms  kc_Pychoed_1
                       76 ms   77 ms   77 ms   86 ms  kc_Pychoed_2
                        0 ms    1 ms    1 ms    1 ms  Matt
                        0 ms    0 ms    0 ms    0 ms  Matt_Pychoed
                      
                      from timeit import default_timer as timer
                      from statistics import mean, median
                      import random
                      from typing import List, Tuple
                      import math
                      from itertools import accumulate, count
                      from operator import truediv
                      
                      def kc(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0.0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if (new_average >= best_average
                                      or math.isclose(new_average, best_average)):
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_1(nums: List[int]) -> List[int]:
                          """Return list of lengths of max average prefix reductions."""
                      
                          def max_prefix_avg(arr: List[int]) -> Tuple[float, int]:
                              """Return value and length of max average prefix in arr"""
                              if len(arr) == 0:
                                  return (-math.inf, 0)
                              
                              best_length = 1
                              best_average = -math.inf
                              running_sum = 0
                      
                              for i, x in enumerate(arr, 1):
                                  running_sum += x
                                  new_average = running_sum / i
                                  
                                  if new_average >= best_average:
                                      
                                      best_average = new_average
                                      best_length = i
                      
                              return (best_average, best_length)
                      
                          removed_lengths = []
                          total_removed = 0
                      
                          while total_removed < len(nums):
                              _, new_removal = max_prefix_avg(nums[total_removed:])
                              removed_lengths.append(new_removal)
                              total_removed += new_removal
                      
                          return removed_lengths
                      
                      def kc_Pychoed_2(nums):
                          removals = []
                          while nums:
                              averages = map(truediv, accumulate(nums), count(1))
                              remove = max(zip(averages, count(1)))[1]
                              removals.append(remove)
                              nums = nums[remove:]
                          return removals
                      
                      # Lengths of the segments in the upper convex hull
                      # of the cumulative sum graph
                      def Matt(arr):
                          if len(arr) < 2:
                              if len(arr) < 1:
                                  return []
                              else:
                                  return [1]
                          
                          hull = [(0, 0),(1, arr[0])]
                          for x in range(2, len(arr)+1):
                              # this has x coordinate x-1
                              prevPoint = hull[len(hull) - 1]
                              # next point in cumulative sum
                              point = (x, prevPoint[1] + arr[x-1])
                              # remove points not on the convex hull
                              while len(hull) >= 2:
                                  p0 = hull[len(hull)-2]
                                  dx0 = prevPoint[0] - p0[0]
                                  dy0 = prevPoint[1] - p0[1]
                                  dx1 = x - prevPoint[0]
                                  dy1 = point[1] - prevPoint[1]
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                                  prevPoint = p0
                              hull.append(point)
                          
                          return [hull[i+1][0] - hull[i][0] for i in range(0, len(hull)-1)]
                      
                      def pairwise(lst):
                          return zip(lst, lst[1:])
                      
                      def Matt_Pychoed(arr):
                          hull = [(0, 0)]
                          for x, y in enumerate(accumulate(arr), 1):
                              while len(hull) >= 2:
                                  (x0, y0), (x1, y1) = hull[-2:]
                                  dx0 = x1 - x0
                                  dy0 = y1 - y0
                                  dx1 = x - x1
                                  dy1 = y - y1
                                  if dy1*dx0 < dy0*dx1:
                                      break
                                  hull.pop()
                              hull.append((x, y))
                          return [q[0] - p[0] for p, q in pairwise(hull)]
                      
                      funcs = kc, kc_Pychoed_1, kc_Pychoed_2, Matt, Matt_Pychoed
                      stats = min, median, mean, max
                      tss = [[] for _ in funcs]
                      for r in range(1, 21):
                          print(f'After round {r}:')
                          arr = random.choices(range(1, 1001), k=100_000)
                          # arr = list(range(1000, 1, -1))
                          expect = None
                          print(*(f'{stat.__name__:^7}' for stat in stats))
                          for func, ts in zip(funcs, tss):
                              t0 = timer()
                              result = func(arr)
                              t1 = timer()
                              ts.append(t1 - t0)
                              if expect is None:
                                  expect = result
                              assert result == expect
                              print(*('%3d ms ' % (stat(ts) * 1e3) for stat in stats), func.__name__)
                          print()
                      

                      How to apply one signature test to multiple positionals

                      copy iconCopydownload iconDownload
                      subset RealOrMeasure where Real | Measure;
                      multi infix:<+> ( RealOrMeasure:D $left, RealOrMeasure:D $right )  {
                          given $left, $right {
                             when Real,    Real    { nextsame }
                             when Real,    Measure { $right.clone.add-const($left)  }
                             when Measure, Real    {  $left.clone.add-const($right) }
                             when Measure, Measure { my ($result, $argument) = infix-prep $left, $right;
                                                     $result.add($argument)}}
                      
                      }
                      
                      class Foo { 
                          method Int { 110 };
                      } 
                      multi t( Int() $x ) { $x + 1 };
                      multi t( Real $x ) { $x.Int + 11 };
                      
                      say t( 0 );
                      say t( 0.1 );
                      say t( Foo.new );
                      

                      Replacing whole string is faster than replacing only its first character

                      copy iconCopydownload iconDownload
                      $ # .match only looks at the first position regardless
                      $ python -m timeit --setup "import re; p=re.compile('a'); string='x'*100000" "p.match(string)"
                      2000000 loops, best of 5: 155 nsec per loop
                      $ python -m timeit --setup "import re; p=re.compile('^a'); string='x'*100000" "p.match(string)"
                      2000000 loops, best of 5: 157 nsec per loop
                      $ # .search looks at every position, even if there is an anchor
                      $ python -m timeit --setup "import re; p=re.compile('a'); string='x'*100000" "p.search(string)"
                      10000 loops, best of 5: 22.4 usec per loop
                      $ # and the anchor only adds complexity to the matching process
                      $ python -m timeit --setup "import re; p=re.compile('^a'); string='x'*100000" "p.search(string)"
                      500 loops, best of 5: 746 usec per loop
                      
                          if (prefix_len == 1) {
                              /* pattern starts with a literal character */
                              SRE_CHAR c = (SRE_CHAR) prefix[0];
                      #if SIZEOF_SRE_CHAR < 4
                              if ((SRE_CODE) c != prefix[0])
                                  return 0; /* literal can't match: doesn't fit in char width */
                      #endif
                              end = (SRE_CHAR *)state->end;
                              state->must_advance = 0;
                              while (ptr < end) {
                                  while (*ptr != c) {
                                      if (++ptr >= end)
                                          return 0;
                                  }
                                  ...
                      
                      $ # .match only looks at the first position regardless
                      $ python -m timeit --setup "import re; p=re.compile('a'); string='x'*100000" "p.match(string)"
                      2000000 loops, best of 5: 155 nsec per loop
                      $ python -m timeit --setup "import re; p=re.compile('^a'); string='x'*100000" "p.match(string)"
                      2000000 loops, best of 5: 157 nsec per loop
                      $ # .search looks at every position, even if there is an anchor
                      $ python -m timeit --setup "import re; p=re.compile('a'); string='x'*100000" "p.search(string)"
                      10000 loops, best of 5: 22.4 usec per loop
                      $ # and the anchor only adds complexity to the matching process
                      $ python -m timeit --setup "import re; p=re.compile('^a'); string='x'*100000" "p.search(string)"
                      500 loops, best of 5: 746 usec per loop
                      
                          if (prefix_len == 1) {
                              /* pattern starts with a literal character */
                              SRE_CHAR c = (SRE_CHAR) prefix[0];
                      #if SIZEOF_SRE_CHAR < 4
                              if ((SRE_CODE) c != prefix[0])
                                  return 0; /* literal can't match: doesn't fit in char width */
                      #endif
                              end = (SRE_CHAR *)state->end;
                              state->must_advance = 0;
                              while (ptr < end) {
                                  while (*ptr != c) {
                                      if (++ptr >= end)
                                          return 0;
                                  }
                                  ...
                      

                      Why doesn't GHC recognize the function as linear?

                      copy iconCopydownload iconDownload
                      sendToPeer :: Peer Idle %1-> IO (Peer Idle)
                      sendToPeer c = pure c
                      
                      sendToPeer :: Peer Idle %1-> Int -> Peer Busy
                      sendToPeer (Peer d) n = Peer d
                      
                      sendToPeer :: Peer Idle %1-> IO (Peer Idle)
                      sendToPeer c = pure c
                      
                      sendToPeer :: Peer Idle %1-> Int -> Peer Busy
                      sendToPeer (Peer d) n = Peer d
                      
                      {-# LANGUAGE LinearTypes #-}
                      
                      module Lib where
                      
                      import Prelude.Linear
                      import Control.Functor.Linear as Control
                      import qualified Prelude as NonLinear
                      import qualified System.IO.Linear as Linear
                      
                      data Peer st = Peer String deriving Show
                      
                      data Idle
                      data Busy
                      
                      sendToPeer :: Peer Idle %1-> Int -> Linear.IO (Peer Busy)
                      sendToPeer (Peer d) n = Control.pure (Peer d)
                      

                      Why is SFINAE for one of the std::basic_string constructors so restrictive?

                      copy iconCopydownload iconDownload
                      __not_<is_convertible<const _Tp&, const _CharT*>>>::value
                      
                      constexpr basic_string( const CharT* s,
                                              const Allocator& alloc = Allocator() ); //(5)
                      
                      template< class T >
                      explicit basic_string( const T& t,
                                             const Allocator& alloc = Allocator() ); //(10)
                      
                      __not_<is_convertible<const _Tp&, const _CharT*>>>::value
                      
                      constexpr basic_string( const CharT* s,
                                              const Allocator& alloc = Allocator() ); //(5)
                      
                      template< class T >
                      explicit basic_string( const T& t,
                                             const Allocator& alloc = Allocator() ); //(10)
                      
                      class tstring : public std::string
                      {
                      public:
                        tstring() : std::string() {}
                        tstring(tstring&& s) : std::string(std::move(s)) {}
                      };
                      

                      How to combine and then branch in MonadPlus/Alternative

                      copy iconCopydownload iconDownload
                      do
                        let acts = do more actions
                        (do x <- m; acts; ...) <|> (do y <- n; acts; ...)
                      
                      data Coyoneda f a where       
                          Coyoneda :: (b -> a) -> f b -> Coyoneda f a  
                      
                      Alternative f => Alternative (Coyoneda f)
                      MonadPlus f => MonadPlus (Coyoneda f)
                      
                      sandwich :: (Foldable f, MonadPlus m, Monad m) 
                               => m x 
                               -> f (Coyoneda m (m a)) 
                               -> m a
                      sandwich more = join . lowerCoyoneda . hoistCoyoneda (<* more) . asum 
                      
                      sandwich more [Coyoneda m xCont, Coyoneda n yCont]
                      
                      data Coyoneda f a where       
                          Coyoneda :: (b -> a) -> f b -> Coyoneda f a  
                      
                      Alternative f => Alternative (Coyoneda f)
                      MonadPlus f => MonadPlus (Coyoneda f)
                      
                      sandwich :: (Foldable f, MonadPlus m, Monad m) 
                               => m x 
                               -> f (Coyoneda m (m a)) 
                               -> m a
                      sandwich more = join . lowerCoyoneda . hoistCoyoneda (<* more) . asum 
                      
                      sandwich more [Coyoneda m xCont, Coyoneda n yCont]
                      
                      data Coyoneda f a where       
                          Coyoneda :: (b -> a) -> f b -> Coyoneda f a  
                      
                      Alternative f => Alternative (Coyoneda f)
                      MonadPlus f => MonadPlus (Coyoneda f)
                      
                      sandwich :: (Foldable f, MonadPlus m, Monad m) 
                               => m x 
                               -> f (Coyoneda m (m a)) 
                               -> m a
                      sandwich more = join . lowerCoyoneda . hoistCoyoneda (<* more) . asum 
                      
                      sandwich more [Coyoneda m xCont, Coyoneda n yCont]
                      
                      data Coyoneda f a where       
                          Coyoneda :: (b -> a) -> f b -> Coyoneda f a  
                      
                      Alternative f => Alternative (Coyoneda f)
                      MonadPlus f => MonadPlus (Coyoneda f)
                      
                      sandwich :: (Foldable f, MonadPlus m, Monad m) 
                               => m x 
                               -> f (Coyoneda m (m a)) 
                               -> m a
                      sandwich more = join . lowerCoyoneda . hoistCoyoneda (<* more) . asum 
                      
                      sandwich more [Coyoneda m xCont, Coyoneda n yCont]
                      
                      do
                        e <- (Left <$> m) <|> (Right <$> n)
                        more actions
                        case e of
                          Left x -> fx x
                          Right y -> fy y
                      
                      do
                        e <- (fx <$> m) <|> (fy <$> n)
                        more actions
                        e
                      
                      do
                        e <- (Left <$> m) <|> (Right <$> n)
                        more actions
                        case e of
                          Left x -> fx x
                          Right y -> fy y
                      
                      do
                        e <- (fx <$> m) <|> (fy <$> n)
                        more actions
                        e
                      

                      Where to put formatMsgNoLookups in the Log4j XML configuration file

                      copy iconCopydownload iconDownload
                      log4j2.formatMsgNoLookups
                      
                      -Dlog4j2.formatMsgNoLookups=true
                      
                      java -Dlog4j2.formatMsgNoLookups=true -jar myapp.jar
                      
                      log4j2.formatMsgNoLookups
                      
                      -Dlog4j2.formatMsgNoLookups=true
                      
                      java -Dlog4j2.formatMsgNoLookups=true -jar myapp.jar
                      
                      log4j2.formatMsgNoLookups
                      
                      -Dlog4j2.formatMsgNoLookups=true
                      
                      java -Dlog4j2.formatMsgNoLookups=true -jar myapp.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      java -version
                      
                      find yourReleaseDir -type f -name log4j\*jar
                      
                       Log4jReleaseVersion: A.B.C
                      
                      lsof | grep log4j
                      
                      ps -ef | egrep "(java|jdk)"    #OR: | grep -v grep
                      
                      java ShowClassVersions.java app_server_dir |grep log4j
                      app_server_dir/somewebapp.war => WEB-INF/lib/log4j2-core.jar
                      
                      / **
                      * Converts a property name string into a list of tokens. This will strip a prefix of {@code log4j},
                      * {@code log4j2}, {@code Log4j}, or {@code org.apache.logging.log4j}, along with separators of
                      * dash {@code -}, dot {@code.}, underscore {@code _}, and slash {@code /}. Tokens can also be separated
                      * by camel case conventions without needing a separator character in between.
                      *
                      * @param value property name
                      * @return the property broken into lower case tokens
                      * /
                      
                      package org.apache.logging.log4j.core.pattern;
                      
                      import org.apache.logging.log4j.core.util.Constants;
                      import org.junit.Test;
                      
                      import static org.junit.Assert.assertTrue;
                      
                      / **
                       *
                       * /
                      
                      public class Log4jParameterTest {
                          static {
                              // Test Ok. All working
                      // System.setProperty ("log4j2.formatMsgNoLookups", "true");
                      // System.setProperty ("log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("Log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("org.apache.logging.log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("log4j2-formatMsgNoLookups", "true");
                      // System.setProperty ("log4j2_formatMsgNoLookups", "true");
                              System.setProperty ("log4j2 / formatMsgNoLookups", "true");
                              // Test KO. All fail
                      // System.setProperty ("log5j2.formatMsgNoLookups", "true");
                      // System.setProperty ("log5j2-formatMsgNoLookups", "true");
                          }
                          @Test
                          public void testLookupEnabledByDefault () {
                              assertTrue ("Lookups deactivated", Constants.FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS);
                      
                          }
                      }
                      
                      / **
                      * Converts a property name string into a list of tokens. This will strip a prefix of {@code log4j},
                      * {@code log4j2}, {@code Log4j}, or {@code org.apache.logging.log4j}, along with separators of
                      * dash {@code -}, dot {@code.}, underscore {@code _}, and slash {@code /}. Tokens can also be separated
                      * by camel case conventions without needing a separator character in between.
                      *
                      * @param value property name
                      * @return the property broken into lower case tokens
                      * /
                      
                      package org.apache.logging.log4j.core.pattern;
                      
                      import org.apache.logging.log4j.core.util.Constants;
                      import org.junit.Test;
                      
                      import static org.junit.Assert.assertTrue;
                      
                      / **
                       *
                       * /
                      
                      public class Log4jParameterTest {
                          static {
                              // Test Ok. All working
                      // System.setProperty ("log4j2.formatMsgNoLookups", "true");
                      // System.setProperty ("log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("Log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("org.apache.logging.log4j.formatMsgNoLookups", "true");
                      // System.setProperty ("log4j2-formatMsgNoLookups", "true");
                      // System.setProperty ("log4j2_formatMsgNoLookups", "true");
                              System.setProperty ("log4j2 / formatMsgNoLookups", "true");
                              // Test KO. All fail
                      // System.setProperty ("log5j2.formatMsgNoLookups", "true");
                      // System.setProperty ("log5j2-formatMsgNoLookups", "true");
                          }
                          @Test
                          public void testLookupEnabledByDefault () {
                              assertTrue ("Lookups deactivated", Constants.FORMAT_MESSAGES_PATTERN_DISABLE_LOOKUPS);
                      
                          }
                      }
                      

                      Repeating triangle pattern in Python

                      copy iconCopydownload iconDownload
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      n = int(input("n = "))
                      
                      rows = n ** 2
                      base = n * 2 - 1
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          a_space = " " * (n - triangle - 1) * base
                          b_space = " " * (n - level - 1)
                      
                          line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                          print(line)
                      
                      for row in range(rows):
                          triangle = row // n
                          level = row % n
                      
                          print(triangle, level)
                      
                      a_space = " " * (n - triangle - 1) * base
                      b_space = " " * (n - level - 1)
                      
                      a_space
                      
                      "*" * (level * 2 + 1)
                      
                      b_space + "*" * (level * 2 + 1) + b_space
                      
                      (b_space + "*" * (level * 2 + 1) + b_space) * (triangle * 2 + 1)
                      
                      line = (a_space + (b_space + "*" * (level * 2 + 1) + b_space)
                              * (triangle * 2 + 1)).rstrip()
                      
                      print(line)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      def tri(n):
                         r = [(s:=(' '*(((2*n-1)-(2*i-1))//2)))+('*'*(2*i-1))+s for i in range(1, n+1)]
                         return r
                      
                      def triangle(n):
                         v = [''.join(j) for i in range(n+1) for j in zip(*[tri(n) for _ in range(2*i-1)])]
                         return '\n'.join((s:=' '*((len(v[-1]) - len(i))//2))+i+s for i in v) 
                      
                      for i in range(1, 4):
                         print(triangle(i))
                         print('-'*25)
                      
                      *
                      -------------------------
                          *    
                         ***   
                       *  *  * 
                      *********
                      -------------------------
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      -------------------------
                      
                      def tri(n):
                         r = [(s:=(' '*(((2*n-1)-(2*i-1))//2)))+('*'*(2*i-1))+s for i in range(1, n+1)]
                         return r
                      
                      def triangle(n):
                         v = [''.join(j) for i in range(n+1) for j in zip(*[tri(n) for _ in range(2*i-1)])]
                         return '\n'.join((s:=' '*((len(v[-1]) - len(i))//2))+i+s for i in v) 
                      
                      for i in range(1, 4):
                         print(triangle(i))
                         print('-'*25)
                      
                      *
                      -------------------------
                          *    
                         ***   
                       *  *  * 
                      *********
                      -------------------------
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      -------------------------
                      
                      def tri(n):
                         r = [(s:=(' '*(((2*n-1)-(2*i-1))//2)))+('*'*(2*i-1))+s for i in range(1, n+1)]
                         return r
                      
                      def triangle(n):
                         v = [''.join(j) for i in range(n+1) for j in zip(*[tri(n) for _ in range(2*i-1)])]
                         return '\n'.join((s:=' '*((len(v[-1]) - len(i))//2))+i+s for i in v) 
                      
                      for i in range(1, 4):
                         print(triangle(i))
                         print('-'*25)
                      
                      *
                      -------------------------
                          *    
                         ***   
                       *  *  * 
                      *********
                      -------------------------
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      -------------------------
                      
                      import sys
                      
                      n = int(sys.argv[1])
                      
                      def drawtriangle(num_lines):
                          # prepares the inner triagle in a list and return it together with its width (size).
                          size = (2*num_lines)-1
                          triangle = []
                          for i in range(num_lines):
                              white_side = num_lines - i - 1
                              asterisks = 2*i + 1
                              triangle.append(" "*white_side + "*"*asterisks + " "*white_side)
                          return triangle, size
                      
                      def main(num_lines):
                          tr, tr_size = drawtriangle(num_lines)
                      
                          for j in range(num_lines):
                              for line in tr:
                                  white_triangles = n - j - 1
                                  white_size = tr_size * white_triangles
                                  line_repeat = (2*j) + 1
                                  print(" "*white_size + line*line_repeat + " "*white_size)
                      
                      main(n)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      import sys
                      
                      n = int(sys.argv[1])
                      
                      def drawtriangle(num_lines):
                          # prepares the inner triagle in a list and return it together with its width (size).
                          size = (2*num_lines)-1
                          triangle = []
                          for i in range(num_lines):
                              white_side = num_lines - i - 1
                              asterisks = 2*i + 1
                              triangle.append(" "*white_side + "*"*asterisks + " "*white_side)
                          return triangle, size
                      
                      def main(num_lines):
                          tr, tr_size = drawtriangle(num_lines)
                      
                          for j in range(num_lines):
                              for line in tr:
                                  white_triangles = n - j - 1
                                  white_size = tr_size * white_triangles
                                  line_repeat = (2*j) + 1
                                  print(" "*white_size + line*line_repeat + " "*white_size)
                      
                      main(n)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      import sys
                      
                      n = int(sys.argv[1])
                      
                      def drawtriangle(num_lines):
                          # prepares the inner triagle in a list and return it together with its width (size).
                          size = (2*num_lines)-1
                          triangle = []
                          for i in range(num_lines):
                              white_side = num_lines - i - 1
                              asterisks = 2*i + 1
                              triangle.append(" "*white_side + "*"*asterisks + " "*white_side)
                          return triangle, size
                      
                      def main(num_lines):
                          tr, tr_size = drawtriangle(num_lines)
                      
                          for j in range(num_lines):
                              for line in tr:
                                  white_triangles = n - j - 1
                                  white_size = tr_size * white_triangles
                                  line_repeat = (2*j) + 1
                                  print(" "*white_size + line*line_repeat + " "*white_size)
                      
                      main(n)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      import sys
                      
                      n = int(sys.argv[1])
                      
                      def drawtriangle(num_lines):
                          # prepares the inner triagle in a list and return it together with its width (size).
                          size = (2*num_lines)-1
                          triangle = []
                          for i in range(num_lines):
                              white_side = num_lines - i - 1
                              asterisks = 2*i + 1
                              triangle.append(" "*white_side + "*"*asterisks + " "*white_side)
                          return triangle, size
                      
                      def main(num_lines):
                          tr, tr_size = drawtriangle(num_lines)
                      
                          for j in range(num_lines):
                              for line in tr:
                                  white_triangles = n - j - 1
                                  white_size = tr_size * white_triangles
                                  line_repeat = (2*j) + 1
                                  print(" "*white_size + line*line_repeat + " "*white_size)
                      
                      main(n)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      import sys
                      
                      n = int(sys.argv[1])
                      
                      def drawtriangle(num_lines):
                          # prepares the inner triagle in a list and return it together with its width (size).
                          size = (2*num_lines)-1
                          triangle = []
                          for i in range(num_lines):
                              white_side = num_lines - i - 1
                              asterisks = 2*i + 1
                              triangle.append(" "*white_side + "*"*asterisks + " "*white_side)
                          return triangle, size
                      
                      def main(num_lines):
                          tr, tr_size = drawtriangle(num_lines)
                      
                          for j in range(num_lines):
                              for line in tr:
                                  white_triangles = n - j - 1
                                  white_size = tr_size * white_triangles
                                  line_repeat = (2*j) + 1
                                  print(" "*white_size + line*line_repeat + " "*white_size)
                      
                      main(n)
                      
                      *
                      
                          *
                         ***
                       *  *  *
                      *********
                      
                                  *
                                 ***
                                *****
                             *    *    *
                            ***  ***  ***
                           ***************
                        *    *    *    *    *
                       ***  ***  ***  ***  ***
                      *************************
                      
                                              *
                                             ***
                                            *****
                                           *******
                                       *      *      *
                                      ***    ***    ***
                                     *****  *****  *****
                                    *********************
                                *      *      *      *      *
                               ***    ***    ***    ***    ***
                              *****  *****  *****  *****  *****
                             ***********************************
                         *      *      *      *      *      *      *
                        ***    ***    ***    ***    ***    ***    ***
                       *****  *****  *****  *****  *****  *****  *****
                      *************************************************
                      
                      rows = int(input())
                      p = 2 * rows *(rows - 1)  # Variable to print the left most spaces
                      x = " "
                      for i in range(rows):  # For every row
                          space = 2 * (rows - 1)  # Space variable to print spaces after an asterisk when needed
                          for j in range(rows):  # For every row inside the row
                              print(p * x, end="")  # print the left most spaces
                              for k in range(2*(i + 1) - 1): 
                                  print((2*(j + 1) - 1) * "*", end = "")  # Print the asterisk(s) based on the row number
                                  print(space * x, end = "")  # Print spaces(s) after the asterisk(s)
                              space -= 2  # Decrement the number of spaces to be printed after an asterisk for every row
                              p -= 1  # Every row has one lesser space on the left
                              print()  # Print a new line after every row
                          p -= (rows - 1)  # Update the number of spaces to be printed on the left most side for every outer row
                      
                                              *      
                                             ***    
                                            *****  
                                           *******
                                       *      *      *      
                                      ***    ***    ***    
                                     *****  *****  *****  
                                    *********************
                                *      *      *      *      *      
                               ***    ***    ***    ***    ***    
                              *****  *****  *****  *****  *****  
                             ***********************************
                         *      *      *      *      *      *      *      
                        ***    ***    ***    ***    ***    ***    ***    
                       *****  *****  *****  *****  *****  *****  *****  
                      *************************************************
                      
                                                              *        
                                                             ***      
                                                            *****    
                                                           *******  
                                                          *********
                                                     *        *        *        
                                                    ***      ***      ***      
                                                   *****    *****    *****    
                                                  *******  *******  *******  
                                                 ***************************
                                            *        *        *        *        *        
                                           ***      ***      ***      ***      ***
                                          *****    *****    *****    *****    *****
                                         *******  *******  *******  *******  *******
                                        *********************************************
                                   *        *        *        *        *        *        *
                                  ***      ***      ***      ***      ***      ***      ***
                                 *****    *****    *****    *****    *****    *****    *****
                                *******  *******  *******  *******  *******  *******  *******
                               ***************************************************************
                          *        *        *        *        *        *        *        *        *
                         ***      ***      ***      ***      ***      ***      ***      ***      ***
                        *****    *****    *****    *****    *****    *****    *****    *****    *****
                       *******  *******  *******  *******  *******  *******  *******  *******  *******
                      *********************************************************************************
                      
                      rows = int(input())
                      p = 2 * rows *(rows - 1)  # Variable to print the left most spaces
                      x = " "
                      for i in range(rows):  # For every row
                          space = 2 * (rows - 1)  # Space variable to print spaces after an asterisk when needed
                          for j in range(rows):  # For every row inside the row
                              print(p * x, end="")  # print the left most spaces
                              for k in range(2*(i + 1) - 1): 
                                  print((2*(j + 1) - 1) * "*", end = "")  # Print the asterisk(s) based on the row number
                                  print(space * x, end = "")  # Print spaces(s) after the asterisk(s)
                              space -= 2  # Decrement the number of spaces to be printed after an asterisk for every row
                              p -= 1  # Every row has one lesser space on the left
                              print()  # Print a new line after every row
                          p -= (rows - 1)  # Update the number of spaces to be printed on the left most side for every outer row
                      
                                              *      
                                             ***    
                                            *****  
                                           *******
                                       *      *      *      
                                      ***    ***    ***    
                                     *****  *****  *****  
                                    *********************
                                *      *      *      *      *      
                               ***    ***    ***    ***    ***    
                              *****  *****  *****  *****  *****  
                             ***********************************
                         *      *      *      *      *      *      *      
                        ***    ***    ***    ***    ***    ***    ***    
                       *****  *****  *****  *****  *****  *****  *****  
                      *************************************************
                      
                                                              *        
                                                             ***      
                                                            *****    
                                                           *******  
                                                          *********
                                                     *        *        *        
                                                    ***      ***      ***      
                                                   *****    *****    *****    
                                                  *******  *******  *******  
                                                 ***************************
                                            *        *        *        *        *        
                                           ***      ***      ***      ***      ***
                                          *****    *****    *****    *****    *****
                                         *******  *******  *******  *******  *******
                                        *********************************************
                                   *        *        *        *        *        *        *
                                  ***      ***      ***      ***      ***      ***      ***
                                 *****    *****    *****    *****    *****    *****    *****
                                *******  *******  *******  *******  *******  *******  *******
                               ***************************************************************
                          *        *        *        *        *        *        *        *        *
                         ***      ***      ***      ***      ***      ***      ***      ***      ***
                        *****    *****    *****    *****    *****    *****    *****    *****    *****
                       *******  *******  *******  *******  *******  *******  *******  *******  *******
                      *********************************************************************************
                      
                      rows = int(input())
                      p = 2 * rows *(rows - 1)  # Variable to print the left most spaces
                      x = " "
                      for i in range(rows):  # For every row
                          space = 2 * (rows - 1)  # Space variable to print spaces after an asterisk when needed
                          for j in range(rows):  # For every row inside the row
                              print(p * x, end="")  # print the left most spaces
                              for k in range(2*(i + 1) - 1): 
                                  print((2*(j + 1) - 1) * "*", end = "")  # Print the asterisk(s) based on the row number
                                  print(space * x, end = "")  # Print spaces(s) after the asterisk(s)
                              space -= 2  # Decrement the number of spaces to be printed after an asterisk for every row
                              p -= 1  # Every row has one lesser space on the left
                              print()  # Print a new line after every row
                          p -= (rows - 1)  # Update the number of spaces to be printed on the left most side for every outer row
                      
                                              *      
                                             ***    
                                            *****  
                                           *******
                                       *      *      *      
                                      ***    ***    ***    
                                     *****  *****  *****  
                                    *********************
                                *      *      *      *      *      
                               ***    ***    ***    ***    ***    
                              *****  *****  *****  *****  *****  
                             ***********************************
                         *      *      *      *      *      *      *      
                        ***    ***    ***    ***    ***    ***    ***    
                       *****  *****  *****  *****  *****  *****  *****  
                      *************************************************
                      
                                                              *        
                                                             ***      
                                                            *****    
                                                           *******  
                                                          *********
                                                     *        *        *        
                                                    ***      ***      ***      
                                                   *****    *****    *****    
                                                  *******  *******  *******  
                                                 ***************************
                                            *        *        *        *        *        
                                           ***      ***      ***      ***      ***
                                          *****    *****    *****    *****    *****
                                         *******  *******  *******  *******  *******
                                        *********************************************
                                   *        *        *        *        *        *        *
                                  ***      ***      ***      ***      ***      ***      ***
                                 *****    *****    *****    *****    *****    *****    *****
                                *******  *******  *******  *******  *******  *******  *******
                               ***************************************************************
                          *        *        *        *        *        *        *        *        *
                         ***      ***      ***      ***      ***      ***      ***      ***      ***
                        *****    *****    *****    *****    *****    *****    *****    *****    *****
                       *******  *******  *******  *******  *******  *******  *******  *******  *******
                      *********************************************************************************
                      
                      size = int(input())
                      
                      for i in range(size):
                          for j in range(i, size):
                              print(" ", end = "")
                          for j in range(i):
                              print("*", end = "")
                          for j in range(i + 1):
                              print("*", end = "")
                          print()
                      
                      def triangle(size):
                          rows = []
                          for i in range(size):
                              row = []
                              for j in range(i + 1, size):
                                  row.append(" ")
                              for j in range(2 * i + 1):    # i + (i+1) = 2*i+1.
                                  row.append("*")
                              for j in range(i + 1, size):  # Let's add spaces at the end, too.
                                  row.append(" ")           # It'll make sense in a moment!
                              rows.append("".join(row))
                          return rows
                      
                      for row in triangle(5):
                          print(row)
                      
                      #     *
                      #    ***
                      #   *****
                      #  *******
                      # *********
                      
                      def triangle(size, block):
                          rows = []
                          for i in range(size):
                              strip = [[] for _ in block]
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))     # Space as wide as the building block
                              for j in range(2 * i + 1):
                                  for s, b in zip(strip, block):
                                      s.append(b)
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))
                              for s in strip:
                                  rows.append("".join(s))
                          return rows
                      
                      
                      # Make a triangle out of ["abc",
                      #                         "def"]:
                      
                      for row in triangle(3, ["abc", "def"]):
                          print(row)
                      
                      #       abc
                      #       def
                      #    abcabcabc
                      #    defdefdef
                      # abcabcabcabcabc
                      # defdefdefdefdef
                      
                      fractal = triangle(4, triangle(4, ["*"]))
                      
                      for row in fractal:
                          print(row)
                      
                      #                         *
                      #                        ***
                      #                       *****
                      #                      *******
                      #                  *      *      *
                      #                 ***    ***    ***
                      #                *****  *****  *****
                      #               *********************
                      #           *      *      *      *      *
                      #          ***    ***    ***    ***    ***
                      #         *****  *****  *****  *****  *****
                      #        ***********************************
                      #    *      *      *      *      *      *      *
                      #   ***    ***    ***    ***    ***    ***    ***
                      #  *****  *****  *****  *****  *****  *****  *****
                      # *************************************************
                      
                      for row in triangle(2, triangle(2, triangle(2, ["()"]))):
                          print(row)
                      
                      #                           ()
                      #                         ()()()
                      #                     ()    ()    ()
                      #                   ()()()()()()()()()
                      #         ()                ()                ()
                      #       ()()()            ()()()            ()()()
                      #   ()    ()    ()    ()    ()    ()    ()    ()    ()
                      # ()()()()()()()()()()()()()()()()()()()()()()()()()()()
                      
                      size = int(input())
                      
                      for i in range(size):
                          for j in range(i, size):
                              print(" ", end = "")
                          for j in range(i):
                              print("*", end = "")
                          for j in range(i + 1):
                              print("*", end = "")
                          print()
                      
                      def triangle(size):
                          rows = []
                          for i in range(size):
                              row = []
                              for j in range(i + 1, size):
                                  row.append(" ")
                              for j in range(2 * i + 1):    # i + (i+1) = 2*i+1.
                                  row.append("*")
                              for j in range(i + 1, size):  # Let's add spaces at the end, too.
                                  row.append(" ")           # It'll make sense in a moment!
                              rows.append("".join(row))
                          return rows
                      
                      for row in triangle(5):
                          print(row)
                      
                      #     *
                      #    ***
                      #   *****
                      #  *******
                      # *********
                      
                      def triangle(size, block):
                          rows = []
                          for i in range(size):
                              strip = [[] for _ in block]
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))     # Space as wide as the building block
                              for j in range(2 * i + 1):
                                  for s, b in zip(strip, block):
                                      s.append(b)
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))
                              for s in strip:
                                  rows.append("".join(s))
                          return rows
                      
                      
                      # Make a triangle out of ["abc",
                      #                         "def"]:
                      
                      for row in triangle(3, ["abc", "def"]):
                          print(row)
                      
                      #       abc
                      #       def
                      #    abcabcabc
                      #    defdefdef
                      # abcabcabcabcabc
                      # defdefdefdefdef
                      
                      fractal = triangle(4, triangle(4, ["*"]))
                      
                      for row in fractal:
                          print(row)
                      
                      #                         *
                      #                        ***
                      #                       *****
                      #                      *******
                      #                  *      *      *
                      #                 ***    ***    ***
                      #                *****  *****  *****
                      #               *********************
                      #           *      *      *      *      *
                      #          ***    ***    ***    ***    ***
                      #         *****  *****  *****  *****  *****
                      #        ***********************************
                      #    *      *      *      *      *      *      *
                      #   ***    ***    ***    ***    ***    ***    ***
                      #  *****  *****  *****  *****  *****  *****  *****
                      # *************************************************
                      
                      for row in triangle(2, triangle(2, triangle(2, ["()"]))):
                          print(row)
                      
                      #                           ()
                      #                         ()()()
                      #                     ()    ()    ()
                      #                   ()()()()()()()()()
                      #         ()                ()                ()
                      #       ()()()            ()()()            ()()()
                      #   ()    ()    ()    ()    ()    ()    ()    ()    ()
                      # ()()()()()()()()()()()()()()()()()()()()()()()()()()()
                      
                      size = int(input())
                      
                      for i in range(size):
                          for j in range(i, size):
                              print(" ", end = "")
                          for j in range(i):
                              print("*", end = "")
                          for j in range(i + 1):
                              print("*", end = "")
                          print()
                      
                      def triangle(size):
                          rows = []
                          for i in range(size):
                              row = []
                              for j in range(i + 1, size):
                                  row.append(" ")
                              for j in range(2 * i + 1):    # i + (i+1) = 2*i+1.
                                  row.append("*")
                              for j in range(i + 1, size):  # Let's add spaces at the end, too.
                                  row.append(" ")           # It'll make sense in a moment!
                              rows.append("".join(row))
                          return rows
                      
                      for row in triangle(5):
                          print(row)
                      
                      #     *
                      #    ***
                      #   *****
                      #  *******
                      # *********
                      
                      def triangle(size, block):
                          rows = []
                          for i in range(size):
                              strip = [[] for _ in block]
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))     # Space as wide as the building block
                              for j in range(2 * i + 1):
                                  for s, b in zip(strip, block):
                                      s.append(b)
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))
                              for s in strip:
                                  rows.append("".join(s))
                          return rows
                      
                      
                      # Make a triangle out of ["abc",
                      #                         "def"]:
                      
                      for row in triangle(3, ["abc", "def"]):
                          print(row)
                      
                      #       abc
                      #       def
                      #    abcabcabc
                      #    defdefdef
                      # abcabcabcabcabc
                      # defdefdefdefdef
                      
                      fractal = triangle(4, triangle(4, ["*"]))
                      
                      for row in fractal:
                          print(row)
                      
                      #                         *
                      #                        ***
                      #                       *****
                      #                      *******
                      #                  *      *      *
                      #                 ***    ***    ***
                      #                *****  *****  *****
                      #               *********************
                      #           *      *      *      *      *
                      #          ***    ***    ***    ***    ***
                      #         *****  *****  *****  *****  *****
                      #        ***********************************
                      #    *      *      *      *      *      *      *
                      #   ***    ***    ***    ***    ***    ***    ***
                      #  *****  *****  *****  *****  *****  *****  *****
                      # *************************************************
                      
                      for row in triangle(2, triangle(2, triangle(2, ["()"]))):
                          print(row)
                      
                      #                           ()
                      #                         ()()()
                      #                     ()    ()    ()
                      #                   ()()()()()()()()()
                      #         ()                ()                ()
                      #       ()()()            ()()()            ()()()
                      #   ()    ()    ()    ()    ()    ()    ()    ()    ()
                      # ()()()()()()()()()()()()()()()()()()()()()()()()()()()
                      
                      size = int(input())
                      
                      for i in range(size):
                          for j in range(i, size):
                              print(" ", end = "")
                          for j in range(i):
                              print("*", end = "")
                          for j in range(i + 1):
                              print("*", end = "")
                          print()
                      
                      def triangle(size):
                          rows = []
                          for i in range(size):
                              row = []
                              for j in range(i + 1, size):
                                  row.append(" ")
                              for j in range(2 * i + 1):    # i + (i+1) = 2*i+1.
                                  row.append("*")
                              for j in range(i + 1, size):  # Let's add spaces at the end, too.
                                  row.append(" ")           # It'll make sense in a moment!
                              rows.append("".join(row))
                          return rows
                      
                      for row in triangle(5):
                          print(row)
                      
                      #     *
                      #    ***
                      #   *****
                      #  *******
                      # *********
                      
                      def triangle(size, block):
                          rows = []
                          for i in range(size):
                              strip = [[] for _ in block]
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))     # Space as wide as the building block
                              for j in range(2 * i + 1):
                                  for s, b in zip(strip, block):
                                      s.append(b)
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))
                              for s in strip:
                                  rows.append("".join(s))
                          return rows
                      
                      
                      # Make a triangle out of ["abc",
                      #                         "def"]:
                      
                      for row in triangle(3, ["abc", "def"]):
                          print(row)
                      
                      #       abc
                      #       def
                      #    abcabcabc
                      #    defdefdef
                      # abcabcabcabcabc
                      # defdefdefdefdef
                      
                      fractal = triangle(4, triangle(4, ["*"]))
                      
                      for row in fractal:
                          print(row)
                      
                      #                         *
                      #                        ***
                      #                       *****
                      #                      *******
                      #                  *      *      *
                      #                 ***    ***    ***
                      #                *****  *****  *****
                      #               *********************
                      #           *      *      *      *      *
                      #          ***    ***    ***    ***    ***
                      #         *****  *****  *****  *****  *****
                      #        ***********************************
                      #    *      *      *      *      *      *      *
                      #   ***    ***    ***    ***    ***    ***    ***
                      #  *****  *****  *****  *****  *****  *****  *****
                      # *************************************************
                      
                      for row in triangle(2, triangle(2, triangle(2, ["()"]))):
                          print(row)
                      
                      #                           ()
                      #                         ()()()
                      #                     ()    ()    ()
                      #                   ()()()()()()()()()
                      #         ()                ()                ()
                      #       ()()()            ()()()            ()()()
                      #   ()    ()    ()    ()    ()    ()    ()    ()    ()
                      # ()()()()()()()()()()()()()()()()()()()()()()()()()()()
                      
                      size = int(input())
                      
                      for i in range(size):
                          for j in range(i, size):
                              print(" ", end = "")
                          for j in range(i):
                              print("*", end = "")
                          for j in range(i + 1):
                              print("*", end = "")
                          print()
                      
                      def triangle(size):
                          rows = []
                          for i in range(size):
                              row = []
                              for j in range(i + 1, size):
                                  row.append(" ")
                              for j in range(2 * i + 1):    # i + (i+1) = 2*i+1.
                                  row.append("*")
                              for j in range(i + 1, size):  # Let's add spaces at the end, too.
                                  row.append(" ")           # It'll make sense in a moment!
                              rows.append("".join(row))
                          return rows
                      
                      for row in triangle(5):
                          print(row)
                      
                      #     *
                      #    ***
                      #   *****
                      #  *******
                      # *********
                      
                      def triangle(size, block):
                          rows = []
                          for i in range(size):
                              strip = [[] for _ in block]
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))     # Space as wide as the building block
                              for j in range(2 * i + 1):
                                  for s, b in zip(strip, block):
                                      s.append(b)
                              for j in range(i + 1, size):
                                  for s, b in zip(strip, block):
                                      s.append(" " * len(b))
                              for s in strip:
                                  rows.append("".join(s))
                          return rows
                      
                      
                      # Make a triangle out of ["abc",
                      #                         "def"]:
                      
                      for row in triangle(3, ["abc", "def"]):
                          print(row)
                      
                      #       abc
                      #       def
                      #    abcabcabc
                      #    defdefdef
                      # abcabcabcabcabc
                      # defdefdefdefdef
                      
                      fractal = triangle(4, triangle(4, ["*"]))
                      
                      for row in fractal:
                          print(row)
                      
                      #                         *
                      #                        ***
                      #                       *****
                      #                      *******
                      #                  *      *      *
                      #                 ***    ***    ***
                      #                *****  *****  *****
                      #               *********************
                      #           *      *      *      *      *
                      #          ***    ***    ***    ***    ***
                      #         *****  *****  *****  *****  *****
                      #        ***********************************
                      #    *      *      *      *      *      *      *
                      #   ***    ***    ***    ***    ***    ***    ***
                      #  *****  *****  *****  *****  *****  *****  *****
                      # *************************************************
                      
                      for row in triangle(2, triangle(2, triangle(2, ["()"]))):
                          print(row)
                      
                      #                           ()
                      #                         ()()()
                      #                     ()    ()    ()
                      #                   ()()()()()()()()()
                      #         ()                ()                ()
                      #       ()()()            ()()()            ()()()
                      #   ()    ()    ()    ()    ()    ()    ()    ()    ()
                      # ()()()()()()()()()()()()()()()()()()()()()()()()()()()
                      
                      def print_fractal(n, char='*'):
                          # Width of single triangle
                          base = 2*n - 1
                          
                          # Width of overall figure
                          width = base**2
                          
                          # Lines containing single triangle padded to rectangle of width `base`
                          lines = [f'{(2*line + 1)*char:^{base}}' for line in range(n)]
                          
                          for row in range(n):
                              # Print (2*row + 1) triangle blocks next to each other
                              for line in lines:
                                  print(f'{(2*row + 1)*line:^{width}}')
                      
                      >>> print_fractal(3)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      
                      def make_fractal(n, depth, block=['*']):
                          if not depth:
                              return block
                          
                          width = (2*n - 1)*max(map(len, block))
                          
                          lines = []
                          
                          for row in range(n):
                              for line in block:
                                  lines.append(f'{(2*row + 1)*line:^{width}}')
                          
                          return make_fractal(n, depth - 1, lines)
                      
                      >>> for line in make_fractal(3, 2): print(line)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      >>> for line in make_fractal(2, 3): print(line)
                                   *             
                                  ***            
                                *  *  *          
                               *********         
                          *        *        *    
                         ***      ***      ***   
                       *  *  *  *  *  *  *  *  * 
                      ***************************
                      >>> for line in make_fractal(2, 2, [' . ', '---']): print(line)
                                   .             
                                  ---            
                                .  .  .          
                               ---------         
                          .        .        .    
                         ---      ---      ---   
                       .  .  .  .  .  .  .  .  . 
                      ---------------------------
                      
                      def print_fractal(n, char='*'):
                          # Width of single triangle
                          base = 2*n - 1
                          
                          # Width of overall figure
                          width = base**2
                          
                          # Lines containing single triangle padded to rectangle of width `base`
                          lines = [f'{(2*line + 1)*char:^{base}}' for line in range(n)]
                          
                          for row in range(n):
                              # Print (2*row + 1) triangle blocks next to each other
                              for line in lines:
                                  print(f'{(2*row + 1)*line:^{width}}')
                      
                      >>> print_fractal(3)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      
                      def make_fractal(n, depth, block=['*']):
                          if not depth:
                              return block
                          
                          width = (2*n - 1)*max(map(len, block))
                          
                          lines = []
                          
                          for row in range(n):
                              for line in block:
                                  lines.append(f'{(2*row + 1)*line:^{width}}')
                          
                          return make_fractal(n, depth - 1, lines)
                      
                      >>> for line in make_fractal(3, 2): print(line)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      >>> for line in make_fractal(2, 3): print(line)
                                   *             
                                  ***            
                                *  *  *          
                               *********         
                          *        *        *    
                         ***      ***      ***   
                       *  *  *  *  *  *  *  *  * 
                      ***************************
                      >>> for line in make_fractal(2, 2, [' . ', '---']): print(line)
                                   .             
                                  ---            
                                .  .  .          
                               ---------         
                          .        .        .    
                         ---      ---      ---   
                       .  .  .  .  .  .  .  .  . 
                      ---------------------------
                      
                      def print_fractal(n, char='*'):
                          # Width of single triangle
                          base = 2*n - 1
                          
                          # Width of overall figure
                          width = base**2
                          
                          # Lines containing single triangle padded to rectangle of width `base`
                          lines = [f'{(2*line + 1)*char:^{base}}' for line in range(n)]
                          
                          for row in range(n):
                              # Print (2*row + 1) triangle blocks next to each other
                              for line in lines:
                                  print(f'{(2*row + 1)*line:^{width}}')
                      
                      >>> print_fractal(3)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      
                      def make_fractal(n, depth, block=['*']):
                          if not depth:
                              return block
                          
                          width = (2*n - 1)*max(map(len, block))
                          
                          lines = []
                          
                          for row in range(n):
                              for line in block:
                                  lines.append(f'{(2*row + 1)*line:^{width}}')
                          
                          return make_fractal(n, depth - 1, lines)
                      
                      >>> for line in make_fractal(3, 2): print(line)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      >>> for line in make_fractal(2, 3): print(line)
                                   *             
                                  ***            
                                *  *  *          
                               *********         
                          *        *        *    
                         ***      ***      ***   
                       *  *  *  *  *  *  *  *  * 
                      ***************************
                      >>> for line in make_fractal(2, 2, [' . ', '---']): print(line)
                                   .             
                                  ---            
                                .  .  .          
                               ---------         
                          .        .        .    
                         ---      ---      ---   
                       .  .  .  .  .  .  .  .  . 
                      ---------------------------
                      
                      def print_fractal(n, char='*'):
                          # Width of single triangle
                          base = 2*n - 1
                          
                          # Width of overall figure
                          width = base**2
                          
                          # Lines containing single triangle padded to rectangle of width `base`
                          lines = [f'{(2*line + 1)*char:^{base}}' for line in range(n)]
                          
                          for row in range(n):
                              # Print (2*row + 1) triangle blocks next to each other
                              for line in lines:
                                  print(f'{(2*row + 1)*line:^{width}}')
                      
                      >>> print_fractal(3)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      
                      def make_fractal(n, depth, block=['*']):
                          if not depth:
                              return block
                          
                          width = (2*n - 1)*max(map(len, block))
                          
                          lines = []
                          
                          for row in range(n):
                              for line in block:
                                  lines.append(f'{(2*row + 1)*line:^{width}}')
                          
                          return make_fractal(n, depth - 1, lines)
                      
                      >>> for line in make_fractal(3, 2): print(line)
                                  *            
                                 ***           
                                *****          
                             *    *    *       
                            ***  ***  ***      
                           ***************     
                        *    *    *    *    *  
                       ***  ***  ***  ***  *** 
                      *************************
                      >>> for line in make_fractal(2, 3): print(line)
                                   *             
                                  ***            
                                *  *  *          
                               *********         
                          *        *        *    
                         ***      ***      ***   
                       *  *  *  *  *  *  *  *  * 
                      ***************************
                      >>> for line in make_fractal(2, 2, [' . ', '---']): print(line)
                                   .             
                                  ---            
                                .  .  .          
                               ---------         
                          .        .        .    
                         ---      ---      ---   
                       .  .  .  .  .  .  .  .  . 
                      ---------------------------
                      

                      Typescript Inheritance: Expanding base class object property

                      copy iconCopydownload iconDownload
                      class Wizard extends Human {
                        manaLevel: number
                        declare options: WizardOptions; // <-- declare
                        constructor() {
                          super()
                          this.manaLevel = 100
                          this.options.hat = "pointy" // <-- no problem now
                        }
                      }
                      
                      class Wizard extends Human {
                          manaLevel;
                          options; // <-- this will be here in JavaScript
                          constructor() {
                              super();
                              this.manaLevel = 100;
                              this.options.hat = "pointy";
                          }
                      }
                      
                      console.log(new Wizard()); // runtime error!
                      // this.options is undefined
                      
                      class Wizard extends Human {
                        manaLevel: number
                        declare options: WizardOptions; // <-- declare
                        constructor() {
                          super()
                          this.manaLevel = 100
                          this.options.hat = "pointy" // <-- no problem now
                        }
                      }
                      
                      class Wizard extends Human {
                          manaLevel;
                          options; // <-- this will be here in JavaScript
                          constructor() {
                              super();
                              this.manaLevel = 100;
                              this.options.hat = "pointy";
                          }
                      }
                      
                      console.log(new Wizard()); // runtime error!
                      // this.options is undefined
                      
                      class Wizard extends Human {
                        manaLevel: number
                        declare options: WizardOptions; // <-- declare
                        constructor() {
                          super()
                          this.manaLevel = 100
                          this.options.hat = "pointy" // <-- no problem now
                        }
                      }
                      
                      class Wizard extends Human {
                          manaLevel;
                          options; // <-- this will be here in JavaScript
                          constructor() {
                              super();
                              this.manaLevel = 100;
                              this.options.hat = "pointy";
                          }
                      }
                      
                      console.log(new Wizard()); // runtime error!
                      // this.options is undefined
                      
                      type HumanOptions = {
                        alive: boolean
                        age: number
                      }
                      
                      class Human<Options extends HumanOptions> {
                        id: string
                        options: Options
                      
                        constructor() {
                          this.id = '_' + Math.random()
                      
                          this.options = {
                            alive: true,
                            age: 25,
                          } as Options
                        }
                      }
                      
                      type WizardOptions = {
                        hat: string
                      } & HumanOptions
                      
                      class Wizard extends Human<WizardOptions> {
                        manaLevel: number
                      
                        constructor() {
                          super()
                          this.manaLevel = 100
                          this.options.hat = "pointy"
                        }
                      }
                      

                      Python 3.10 pattern matching (PEP 634) - wildcard in string

                      copy iconCopydownload iconDownload
                      for event in data:
                          match event:
                              case {'id': x} if x.startswith("matchme"): # guard
                                  print(event["message"])
                              case {'id':'anotherid'}:
                                  print(event["message"])
                      
                      match point:
                           case Point(x, y) if x == y:
                               print(f"The point is located on the diagonal Y=X at {x}.")
                           case Point(x, y):
                               print(f"Point is not on the diagonal.")
                      
                      for event in data:
                          match event:
                              case {'id': x} if x.startswith("matchme"): # guard
                                  print(event["message"])
                              case {'id':'anotherid'}:
                                  print(event["message"])
                      
                      match point:
                           case Point(x, y) if x == y:
                               print(f"The point is located on the diagonal Y=X at {x}.")
                           case Point(x, y):
                               print(f"Point is not on the diagonal.")
                      

                      Community Discussions

                      Trending Discussions on pattern
                      • ESlint - Error: Must use import to load ES Module
                      • Match ergonomics and &amp; pattern
                      • Repeatedly removing the maximum average subarray
                      • How to apply one signature test to multiple positionals
                      • Replacing whole string is faster than replacing only its first character
                      • Why doesn't GHC recognize the function as linear?
                      • Why is SFINAE for one of the std::basic_string constructors so restrictive?
                      • How to combine and then branch in MonadPlus/Alternative
                      • Where to put formatMsgNoLookups in the Log4j XML configuration file
                      • Repeating triangle pattern in Python
                      Trending Discussions on pattern

                      QUESTION

                      ESlint - Error: Must use import to load ES Module

                      Asked 2022-Mar-17 at 12:13

                      I am currently setting up a boilerplate with React, Typescript, styled components, webpack etc. and I am getting an error when trying to run eslint:

                      Error: Must use import to load ES Module

                      Here is a more verbose version of the error:

                      /Users/ben/Desktop/development projects/react-boilerplate-styled-context/src/api/api.ts
                        0:0  error  Parsing error: Must use import to load ES Module: /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js
                      require() of ES modules is not supported.
                      require() of /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/lib/definition.js from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/babel-eslint/lib/require-from-eslint.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
                      Instead rename definition.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/ben/Desktop/development projects/react-boilerplate-styled-context/node_modules/eslint/node_modules/eslint-scope/package.json
                      

                      The error occurs in every single one of my .js and .ts/ .tsx files where I only use import or the file doesn't even have an import at all. I understand what the error is saying but I have no idea why it is being thrown when in fact I only use imports or even no imports at all in some files.

                      Here is my package.json where I trigger the linter from using npm run lint:eslint:quiet:

                      {
                        "name": "my-react-boilerplate",
                        "version": "1.0.0",
                        "description": "",
                        "main": "index.tsx",
                        "directories": {
                          "test": "test"
                        },
                        "engines": {
                          "node": ">=14.0.0"
                        },
                        "type": "module",
                        "scripts": {
                          "build": "webpack --config webpack.prod.js",
                          "dev": "webpack serve --config webpack.dev.js",
                          "lint": "npm run typecheck && npm run lint:css && npm run lint:eslint:quiet",
                          "lint:css": "stylelint './src/**/*.{js,ts,tsx}'",
                          "lint:eslint:quiet": "eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet",
                          "lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern",
                          "lint:eslint:fix": "eslint --ext .ts,.tsx,.js,.jsx  ./src --no-error-on-unmatched-pattern --quiet --fix",
                          "test": "cross-env NODE_ENV=test jest --coverage",
                          "test:watch": "cross-env NODE_ENV=test jest --watchAll",
                          "typecheck": "tsc --noEmit",
                          "precommit": "npm run lint"
                        },
                        "lint-staged": {
                          "*.{ts,tsx,js,jsx}": [
                            "npm run lint:eslint:fix",
                            "git add --force"
                          ],
                          "*.{md,json}": [
                            "prettier --write",
                            "git add --force"
                          ]
                        },
                        "husky": {
                          "hooks": {
                            "pre-commit": "npx lint-staged && npm run typecheck"
                          }
                        },
                        "resolutions": {
                          "styled-components": "^5"
                        },
                        "author": "",
                        "license": "ISC",
                        "devDependencies": {
                          "@babel/core": "^7.5.4",
                          "@babel/plugin-proposal-class-properties": "^7.5.0",
                          "@babel/preset-env": "^7.5.4",
                          "@babel/preset-react": "^7.0.0",
                          "@types/history": "^4.7.6",
                          "@types/react": "^17.0.29",
                          "@types/react-dom": "^17.0.9",
                          "@types/react-router": "^5.1.17",
                          "@types/react-router-dom": "^5.1.5",
                          "@types/styled-components": "^5.1.15",
                          "@typescript-eslint/eslint-plugin": "^5.0.0",
                          "babel-cli": "^6.26.0",
                          "babel-eslint": "^10.0.2",
                          "babel-loader": "^8.0.0-beta.6",
                          "babel-polyfill": "^6.26.0",
                          "babel-preset-env": "^1.7.0",
                          "babel-preset-react": "^6.24.1",
                          "babel-preset-stage-2": "^6.24.1",
                          "clean-webpack-plugin": "^4.0.0",
                          "dotenv-webpack": "^7.0.3",
                          "error-overlay-webpack-plugin": "^1.0.0",
                          "eslint": "^8.0.0",
                          "eslint-config-airbnb": "^18.2.0",
                          "eslint-config-prettier": "^8.3.0",
                          "eslint-config-with-prettier": "^6.0.0",
                          "eslint-plugin-compat": "^3.3.0",
                          "eslint-plugin-import": "^2.25.2",
                          "eslint-plugin-jsx-a11y": "^6.2.3",
                          "eslint-plugin-prettier": "^4.0.0",
                          "eslint-plugin-react": "^7.14.2",
                          "eslint-plugin-react-hooks": "^4.2.0",
                          "extract-text-webpack-plugin": "^3.0.2",
                          "file-loader": "^6.2.0",
                          "html-webpack-plugin": "^5.3.2",
                          "husky": "^7.0.2",
                          "prettier": "^2.4.1",
                          "raw-loader": "^4.0.2",
                          "style-loader": "^3.3.0",
                          "stylelint": "^13.13.1",
                          "stylelint-config-recommended": "^5.0.0",
                          "stylelint-config-styled-components": "^0.1.1",
                          "stylelint-processor-styled-components": "^1.10.0",
                          "ts-loader": "^9.2.6",
                          "tslint": "^6.1.3",
                          "typescript": "^4.4.4",
                          "url-loader": "^4.1.1",
                          "webpack": "^5.58.2",
                          "webpack-cli": "^4.2.0",
                          "webpack-dev-server": "^4.3.1",
                          "webpack-merge": "^5.3.0"
                        },
                        "dependencies": {
                          "history": "^4.10.0",
                          "process": "^0.11.10",
                          "react": "^17.0.1",
                          "react-dom": "^17.0.1",
                          "react-router-dom": "^5.2.0",
                          "styled-components": "^5.2.1"
                        }
                      }
                      

                      Here is my .eslintrc file:

                      {
                        "extends": ["airbnb", "prettier"],
                        "parser": "babel-eslint",
                        "plugins": ["prettier", "@typescript-eslint"],
                        "parserOptions": {
                          "ecmaVersion": 8,
                          "ecmaFeatures": {
                            "experimentalObjectRestSpread": true,
                            "impliedStrict": true,
                            "classes": true
                          }
                        },
                        "env": {
                          "browser": true,
                          "node": true,
                          "jest": true
                        },
                        "rules": {
                          "arrow-body-style": ["error", "as-needed"],
                          "class-methods-use-this": 0,
                          "react/jsx-filename-extension": 0,
                          "global-require": 0,
                          "react/destructuring-assignment": 0,
                          "import/named": 2,
                          "linebreak-style": 0,
                          "import/no-dynamic-require": 0,
                          "import/no-named-as-default": 0,
                          "import/no-unresolved": 2,
                          "import/prefer-default-export": 0,
                          "semi": [2, "always"],
                          "max-len": [
                            "error",
                            {
                              "code": 80,
                              "ignoreUrls": true,
                              "ignoreComments": true,
                              "ignoreStrings": true,
                              "ignoreTemplateLiterals": true
                            }
                          ],
                          "new-cap": [
                            2,
                            {
                              "capIsNew": false,
                              "newIsCap": true
                            }
                          ],
                          "no-param-reassign": 0,
                          "no-shadow": 0,
                          "no-tabs": 2,
                          "no-underscore-dangle": 0,
                          "react/forbid-prop-types": [
                            "error",
                            {
                              "forbid": ["any"]
                            }
                          ],
                          "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
                          "react/jsx-no-bind": [
                            "error",
                            {
                              "ignoreRefs": true,
                              "allowArrowFunctions": true,
                              "allowBind": false
                            }
                          ],
                          "react/no-unknown-property": [
                            2,
                            {
                              "ignore": ["itemscope", "itemtype", "itemprop"]
                            }
                          ]
                        }
                      }
                      

                      And i'm not sure if relevant but also my tsconfig.eslint.json file:

                      {
                        "extends": "./tsconfig.json",
                        "include": ["./src/**/*.ts", "./src/**/*.tsx", "./src/**/*.js"],
                        "exclude": ["node_modules/**", "build/**", "coverage/**"]
                      }
                      

                      Not sure if anyone has come across this before? Googling the error does not present any useful forums or raised bugs, most of them just state not to use require in your files which I am not.

                      ANSWER

                      Answered 2022-Mar-15 at 16:08

                      I think the problem is that you are trying to use the deprecated babel-eslint parser, last updated a year ago, which looks like it doesn't support ES6 modules. Updating to the latest parser seems to work, at least for simple linting.

                      So, do this:

                      • In package.json, update the line "babel-eslint": "^10.0.2", to "@babel/eslint-parser": "^7.5.4",. This works with the code above but it may be better to use the latest version, which at the time of writing is 7.16.3.
                      • Run npm i from a terminal/command prompt in the folder
                      • In .eslintrc, update the parser line "parser": "babel-eslint", to "parser": "@babel/eslint-parser",
                      • In .eslintrc, add "requireConfigFile": false, to the parserOptions section (underneath "ecmaVersion": 8,) (I needed this or babel was looking for config files I don't have)
                      • Run the command to lint a file

                      Then, for me with just your two configuration files, the error goes away and I get appropriate linting errors.

                      Source https://stackoverflow.com/questions/69554485

                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                      Vulnerabilities

                      No vulnerabilities reported

                      Install pattern

                      Pattern supports Python 2.7 and Python 3.6. To install Pattern so that it is available in all your scripts, unzip the download and from the command line do:.

                      Support

                      For documentation and examples see the [user documentation](https://github.com/clips/pattern/wiki).

                      DOWNLOAD this Library from

                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      Share this Page

                      share link
                      Consider Popular Natural Language Processing Libraries
                      Try Top Libraries by clips
                      Compare Natural Language Processing Libraries with Highest Support
                      Compare Natural Language Processing Libraries with Highest Quality
                      Compare Natural Language Processing Libraries with Highest Security
                      Compare Natural Language Processing Libraries with Permissive License
                      Compare Natural Language Processing Libraries with Highest Reuse
                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                      over 430 million Knowledge Items
                      Find more libraries
                      Reuse Solution Kits and Libraries Curated by Popular Use Cases
                      Explore Kits

                      Save this library and start creating your kit

                      • © 2022 Open Weaver Inc.