class_docstr: A class for building a MorphLut from a descriptive language
  
  The input patterns is a list of a strings sequences like these::
  
      4:(...
         .1.
         111)->1
  
  (whitespaces including linebreaks are ignored). The option 4
  describes a series of symmetry operations (in this case a
  4-rotation), the pattern is described by:
  
  - . or X - Ignore
  - 1 - Pixel is on
  - 0 - Pixel is off
  
  The result of the operation is described after "->" string.
  
  The default is to return the current pixel value, which is
  returned if no other match is found.
  
  Operations:
  
  - 4 - 4 way rotation
  - N - Negate
  - 1 - Dummy op for no other operation (an op must always be given)
  - M - Mirroring
  
  Example::
  
      lb = LutBuilder(patterns = ["4:(... .1. 111)->1"])
      lut = lb.build_lut()
class_docstr_tok: ["A","class","for","building","a","MorphLut","from","a","descriptive","language","The","input","patterns","is","a","list","of","a","strings","sequences","like","these",":",":","4",":","(","...",".1",".","111",")","-",">","1","(","whitespaces","including","linebreaks","are","ignored",")",".","The","option","4","describes","a","series","of","symmetry","operations","(","in","this","case","a","4-rotation",")",",","the","pattern","is","described","by",":","-",".","or","X","-","Ignore","-","1","-","Pixel","is","on","-","0","-","Pixel","is","off","The","result","of","the","operation","is","described","after","``","-",">","''","string",".","The","default","is","to","return","the","current","pixel","value",",","which","is","returned","if","no","other","match","is","found",".","Operations",":","-","4","-","4","way","rotation","-","N","-","Negate","-","1","-","Dummy","op","for","no","other","operation","(","an","op","must","always","be","given",")","-","M","-","Mirroring","Example",":",":","lb","=","LutBuilder","(","patterns","=","[","``","4",":","(","...",".1",".","111",")","-",">","1","''","]",")","lut","=","lb.build_lut","(",")"]
docstr: string_permute takes a pattern and a permutation and returns the
  string permuted according to the permutation list.
docstr_tok: ["string_permute","takes","a","pattern","and","a","permutation","and","returns","the","string","permuted","according","to","the","permutation","list","."]
code: def _string_permute(
      self, pattern: str, permutation: list[int]
  ) -> str:
      """string_permute takes a pattern and a permutation and returns the
      string permuted according to the permutation list.
      """
      assert len(permutation) == 9
      return "".join(pattern[p] for p in permutation)
  
file_path: pillow/src/PIL/ImageMorph.py
imports: from __future__ import annotations
  import re
  from .None import Image, _imagingmorph
label_desc: Use image node_id 5 for calling the LutBuilder obj's underlying member method code with example usage: obj._string_permute(pattern, permutation) and returns: str