> e='!' python <<<"for c in 'Hello World$e$e$e': print(ord(c),',',end='');"; echo; 72 ,101 ,108 ,108 ,111 ,32 ,87 ,111 ,114 ,108 ,100 ,33 ,33 ,33 , > python <<<$'s="";\nfor i in [72 ,101 ,108 ,108 ,111 ,32 ,87 ,111 ,114 ,108 ,100 ,33 ,33 ,33]:\n s+=chr(i);\nprint(s);' Hello World!!! ## note: <<<"..." and $'...', both especifically provided by bash ¡only!, first creates a stdin data stream, passed implicitly to the invoked program or command, content to be read from that stdin-data stream is the string provided; second ($'...' just gives another mode to quote character strings in bash, the mode you can use escape-sequences for special characters like \n for new-line, \r\n for a Windows-like new line or \b for bell and \033 for &#ESC; or /chr(27), the escape character being used for the known ansi escape sequences in function at almost any terminal, f.i. create colored text with "\033[X,Y,Zm", X=0/1 ~high/low = bright/dark color, Y=foreground color, by default at least 8 at disposition, Z=background color; the standard colors are a combination of red, green and blue with bit values of 1, 2, 4 to be added or or-ed together which results in numbers between 0…7. > python <<<"for p in [33,'[1;31mrot ',33,'[0;32mgrün \033[0;34mblau',12,33,'[0;41mredBg \033[0;42m greenBg \033[0;44m blueBg',33,133,'0m',12]:"$'\n if isinstance(p,int):\n print(chr(int(str(p),8)),end="");\n else:\n print(p,end="");' rot grün blau redBg greenBg blueBg rot grün blau redBg greenBg blueBg > python <<<"for p in [27,'[1;31mrot ',27,'[0;32mgrün \033[0;34mblau',10,27,'[0;41mredBg \033[0;42m greenBg \033[0;44m blueBg',27,91,'0m',10]:"$'\n if isinstance(p,int):\n print(chr(p),end="");\n else:\n print(p,end="");' rot grün blau redBg greenBg blueBg > python >>> [ isinstance(33,int), type(33)==int, type(33), int ] [True, True, , ] >>> ord('A') 65 >>> chr(64+1) 'A' >>> ord('a')-ord('A') 32 >>> ord('Z')-ord('A')+1 26 >>> from functools import reduce; >>> reduce(int.__add__,[1,2,3]); reduce(int.__add__,[4,2,3,1]); 6 10 >>> reduce(str.__add__,[chr(c) for c in [65,98,99]]) 'Abc' >>> bin(64); bin(32); bin(16); '0b1000000' '0b100000' '0b10000' >>> hex(64); oct(64); bin(64); str(64); '0x40' '0o100' '0b1000000' '64' >>> from itertools import starmap; from numpy import base_repr; >>> [base_repr(64,b) for b in (10,16,8,2)] ['64', '40', '100', '1000000'] >>> [(64,b) for b in [10,16,8,2]] [(64, 10), (64, 16), (64, 8), (64, 2)] >>> list(starmap(base_repr,[(64,b) for b in [10,16,8,2]])) ['64', '40', '100', '1000000'] >>> def iterit(lis): ... for e in lis: ... yield e; ... >>> l=[2,4,6,8] >>> iterit(l) >>> list(iterit(l)); tuple(iterit(l)) [2, 4, 6, 8] (2, 4, 6, 8) w3m "https://docs.python.org/3/library/itertools.html" elinks "https://docs.python.org/3/library/functools.html" >>> f=int.__add__; f(1,2); 1+2; 3 3 >>> int.__add__(*[1,2]); 3 >>> def smap(func,pplis): ... for pp in pplis: ... yield func(*pp); ... >>> list(smap(base_repr,[(64,b) for b in [10,16,8,2]])) ['64', '40', '100', '1000000'] >>> list(zip([65,66,67],"ABC")) [(65, 'A'), (66, 'B'), (67, 'C')] >>> def plainmap(func,*plises): ... for pp in zip(*plises): ... yield func(*pp); ... >>> list(plainmap(int.__add__,[1,2,3],[3,2,2])); # aka simply: map(_,…) [4, 4, 5] >>> list(smap(int.__add__,[(1,3),(2,2),(3,2)])); # aka simply: itertools.starmap(_,…) [4, 4, 5] >>> list(smap(int.__add__,zip([1,2,3],[3,2,2]))) # values something like: map(fn,llis) == starmap(fn,*llis) [4, 4, 5] # … but yes, starmap counts hardly available, you need to import it from a library, do that int\at /etc/pythonrc.py or say that works at your ~/.pythonrc.py, for university and school accounts where you don´t have root access the only way it will be possible. >>> def gothru(*the_iterables): # official python makes this function known as 'zip' ... first_itb = next(iter(the_iterables)); ... l0i = [ iter(itb) for itb in the_iterables ]; ... for cur in first_itb: ... yield (cur,*[next(itr) for itr in l0i[1:]]); ... >>> list(gothru([65,66,67,68],"ABCD")); [(65, 'A'), (66, 'B'), (67, 'C'), (68, 'D')] >>> def pairs2seqs(lis0pairs): ... mainitr = iter(lis0pairs); ... fetchapair = list(next(mainitr)); ... cache = [ [el] for el in fetchapair ]; ... def advance(idx,useASmainitr,cache): ... global useASmainitr, cache; ... if len(cache[idx])==0: ... try: ... fetchapair = list(next(useASmainitr)); ... except StopIteration: ... pass; raise; ... for sublis in cache: ... sublis.insert(0,next(fetchapair)); ... try: ... yield cache[idx].pop() ... except: ... pass; ... return [ advance(idx,mainitr,cache) for idx in range(len(cache)) ]; ... File "", line 6 SyntaxError: name 'useASmainitr' is parameter and global >>> def pairs2seqs(lis0pairs): ... mainitr = iter(lis0pairs); ... fetchapair = list(next(mainitr)); ... cache = [ [el] for el in fetchapair ]; ... def advance(idx): ... global mainitr, cache; ... # regarded as a design failure of the Python programming language that you can declare to directly use global variables ... # but that there is no means to declare the same for variables of intermediate level — say level #0 be the global variables ... # level #1 procedures in the global scope and their variable, level #2 subprocedures of global procedures and the variables ... # within these subprocedures. level #1 is called intermediate from the view of a level #2 object, like in our case the ... # subprocedure called ›advance‹ which is a sub-procedure within and as-part-of the global procedure pairs2seqs. ... ## It was impossible to write a functional pairs2seqs, or only very far-fetched, have a global dictionary where you index ... ## by a unique random key generated at procedure entrance of pairs2seqs. All of it just because language designers afar from ... ## Niklaus Wirth have been ignorant to the language feature of procedure nesting. Niklaus Wirth was a university professor ... ## and he designed and implemented a programming language called 'Pascal'. The Turbo Pascal compiler we° had it at school, ... ## BG/BRG St. Martin Villach, I, the name of the person writing at here is Elmar Stellnberger, Dipl.-Ing. my university ... ## professor László Böszörményi at whom I was writing something like parallel language extensions for the SRC M3 compiler, ... ## that Modula 3 the programming language and to be implemented a ForAll loop 4 parallel execution of the loop body. I, me ... ## I can remember having been at a JMLC conference at the uni in Klagenfurt, current location of living of me, still is, ... ## we talked about Niklaus Wirth, who had designed his compiler to give meaningful error messages to the students, ¡main ... ## goal!, for the gcc you need to have studied compiler construction and you need meaningful proficiency in practical ... ## implementation knowledge of compilers, otherwise some error messages of the gcc or clang are simply irrevocably non- ... ## interpretable, I mean they are hard to understand for *me*, and I have certain knowledge about the decisive sub-area ... ## of compiler construction within information science; means I need to think a while, and the error messages contain words ... ## that to my mind are **only** meaningful to someone who wants or already has implemented/hacked the very type of program ... ## that in-at computer science is called ›a compiler‹. I would never write it like this. Simple mindwork to reprhase the ... ## at least more abstract or complicated kinds of error messages in a way that they are uttered/told from the viewpoint of ... ## the programmer and not the viewpoint of the compiler writer/constructor/programmer. That would make the error messages ... ## more simple and open/amenable to whom needs to understand and interprete them day after day. Problem is that most people ... ## here are vaidadosos, the don´t have it an issue, and they would never do anything about it, not even if you ranted or ... ## wanted to force them. Not to say, but is: They are incapable by failed demand to have this and only this right, all ... ## people with adepticism of scripture, all of them have the stringent (and failed°) demand of vaidadosism, and they even ... ## suppose to kill who recuses to make it(‼), I know, we - I and my woman in love - know that, perhaps look at elmstel.info ... ## one or the other thing with contingency to the said or being said issue can be found there – condemam as escrituras, ... ## sabe a minha pessoa sabedoria explicita partires dos contatos e conhecimentos da pessoa pelo lado Christiano como pelas ... ## Buddhistas, más sîm – cada a escritura religios(ist)a não têm outro sentido ou direito em fazer sentido como fazer um ... ## proprio ›lado mau‹, diz-se em mesmo fato est sentido pelo adepto, !!! y mesmo grave mál‼ ... # to say … for variables of intermediate scope, the scope is more or less the data object where a compiler stores local ... # variables and sub-procedures like “def advance(idx):” or: “advance = lambda idx: … ``ohh was a gonna was a very too a ... # hard pit to rewrite »advance« like this here, who would or wanna-do᷅o᷅ prove a thing like that/this-ehh` or give a ... # counter-example to it, what actually is having the work of making the thing proven or ‘refutated’ like the contrary of ... # thing we @ here wanted prove, in this case a single example makes the whole thing refuted, always like this!!! in correct ... # formal science, Mathematics is demanded the mother of all sciences, at least of all nature sciences, consequently the ... # same is valient in everything I, Elmar Stellnberger, Dipl.-Ing. will call a science {to say what is not isn´t kind of aä ... # subject of this text or of writing pairs2seqs/unzip and gothru/zip. So the trick in here is neither ›mainitr‹ nor the ... # ›cache‹ intermediate scope variables exist as global variables. The language directive ‘global’ can only fix the name ... # of our interior level sub-procedure called ›advance‹ to the outermost existant data object. We suppose the variables are ... # not moved to a global scope fromout of a subprocedure, because that would be the most grave {language} design error/failure ... # an implementor or language designer could commit. What isn´t allowed to do. But we achieve it quası̊ to have been done. ... # When I am writing these words, having Python 3.8.14 installed, expect that the implementors of Python will come and that ... # Python 3.8.15 will consequently forbid using variables of intermediate scope, one of the main senses of the Pascal Language, ... # buracos de traseiros têm sempre os seus mesmos melhores, y os vaidadosos sunt em beloved direito de haver-se unos, Ihr ... # *** schweres Recht ***, jã man lernt sie kennen nīe echt, man muß die gewünschten Unrechte schøn entsprechend rechtfertigen ... # können, und dafür braucht mãn daññ nicht `mal mehr als sich selber besser zu haben. Alle anderen Open Source Programme, die ... # dìes als Feature verwendet hätten, könnten dann ab Python 3.8.15 wieder einmal umschreiben oder deren Programm auf der ... # Müllkippe der Open Source Entwicklung belassen (…). Até eu não devo ficar unfair, lo est muitas vezes ordenado indireito, ... # e quem y de aonde eu saiba quem dá monedA as desenvolvidores de OSS?? Um exemplo fica comprovado pela minha pessoa, faça- ... # se ver o projeto Mesa y a cessação do amber branch (Mageia bug report https://bugs.mageia.org/show_bug.cgi?id=31921 for ... # whom wants to see, things proven `till upload at the opensuse build service, but won´t be online there any more, I need to ... # guess). Re-escriberam o »clang« compiler no mesmo tempo que consegiu num imediato de ex-despues da cessação do amber branch # de modo exacto y com puntos decisivas da alteração em qual-o codigo ›clang‹ faz cessar de aceitar codigo com os especiais # compiler features que muito sunt usados nesse parte da Mesa y quasi até de modo somente escasso ou pouco em a qualquiera # outra programma: Efeito exigido y bôm comprido em os alterações no clang, eu devo suponher à pago no mesmo tempo, de # imediato ex-despues de cessar trabalho no amber branch em o projecto Mesa o projecto clang com donor/possessão de Apple, # nesse acaso, cessa compilar o codigo do amber branch — immediatly after work on Mesa/amber_branch had been discontinued # immediately afterwards the special language features needes by Mesa and Amber had been changed in a way that (¿the?) old # code does not compile any more. Means it was at proposition to change the very language features needed in/at there at # the very same time of the time thereafter. No compatibility, no stale-and-warning time given. Branch in the other project # wracked with success and force against what normally is “style of correctness“ in compiler implementation.^^: I know because # I had to rewrite/make the code compile again and the Open Suse Build Service, I knew it from my very first open source days, # provides an environment where you can compile the same program/distribution_package at&for many different Linux distributions # at the same time, IRC #buildservice, or sø. # projecto Mesa (3D graphics for Linux-Xorg/X11, quasi the software or intermediate layer providing the OpenGL interface) >>> def pairs2seqs(lis0pairs): ... global mainitr, cache; ... mainitr = iter(lis0pairs); ... pair1 = list(next(mainitr)); ... pair2 = iter(list(next(mainitr))); ... pair3 = iter(list(next(mainitr))); ... cache = [ [el] for el in pair1 ]; ... for sublis in cache: ... sublis.insert(0,next(pair2)); ... print(sublis); ... for sublis in cache: ... sublis.insert(0,next(pair3)); ... print(sublis); ... return cache; ... >>> pairs2seqs([(65, 'A'), (66, 'B'), (67, 'C'), (68, 'D')]); [66, 65] ['B', 'A'] [67, 66, 65] ['C', 'B', 'A'] [[67, 66, 65], ['C', 'B', 'A']] >>> def pairs2seqs(lis0pairs): ... mainitr = iter(lis0pairs); ... fetchapair = list(next(mainitr)); ... cache = [ [el] for el in fetchapair ]; ... for fetchapair in mainitr: ... elt = iter(list(fetchapair)); ... for sublis in cache: ... sublis.insert(0,next(elt)); ... for sublis in cache: ... sublis.reverse(); ... return cache; ... >>> pairs2seqs([(65, 'A'), (66, 'B'), (67, 'C'), (68, 'D')]); [[65, 66, 67, 68], ['A', 'B', 'C', 'D']] >>> def pairs2seqs(lis0pairs): ... global mainitr, cache; ... mainitr = iter(lis0pairs); ... fetchapair = list(next(mainitr)); ... cache = [ [el] for el in fetchapair ]; ... def advance(idx): ... global mainitr, cache; ... print("8: ",cache[idx]); ... if len(cache[idx])==0: ... print(9); ... try: ... print(10); ... fetchapair = list(next(mainitr)); ... except StopIteration: ... print("end of list "+repr(mainitr)+"reached.",file=sys.stderr); ... return; ... print(14); ... elt = iter(fetchapair); ... print(15); ... for sublis in cache: ... print(16); ... elt = next(elt); print(elt); ... print(17); ... if len(sublis): sublis.insert(0,elt); print(sublis); ... else: cache[idx] = [elt]; print("::",elt); ... print("19: ",cache[idx]); ... try: ... yield cache[idx].pop() ... except StopIteration: ... print("pairs2seqs:advance:: cache has run out of elements but no successful attempt to refetch the elements in cache has been undertaken. unrecoverable error.[!]",file=sys.stderr); ... print("23: ",cache[idx]); ... return [ advance(idx) for idx in range(len(cache)) ]; >>> subll = pairs2seqs([(65, 'A'), (66, 'B'), (67, 'C'), (68, 'D')]); iti = iter(subll[0]); next(iti); 8: [65] 19: [65] 65 >>> next(iti); 23: [] Traceback (most recent call last): File "", line 1, in StopIteration ## impossible!!, lines 8 and 19 needed to have been executed before line 23!!! ## assumedly pairs2seqs would work as is, if the python{3} interpreter did execute correctly >>> def pairs2seqs(lis0pairs): ... global mainitr, cache; ... mainitr = iter(lis0pairs); ... fetchapair = list(next(mainitr)); ... cache = [ [el] for el in fetchapair ]; ... def advance(idx): ... global mainitr, cache; ... if len(cache[idx])==0: ... try: ... fetchapair = list(next(mainitr)); ... except StopIteration: ... pass; raise; ... elt = iter(fetchapair); ... for sublis in cache: ... elt = next(elt); ... if len(sublis): sublis.insert(0,elt); ... else: cache[idx] = [elt]; ... try: ... yield cache[idx].pop() ... except StopIteration: ... print("pairs2seqs:advance:: cache has run out of elements but no successful attempt to refetch the elements in cache has been undertaken. unrecoverable error.[!]",file=sys.stderr); ... return [ advance(idx) for idx in range(len(cache)) ]; vim: [Shift][V] + mark lines that should be copied to file [g][v] ... to copy the same lines again [ESC][:]w! /tmp/x.py :'<,'>w! /tmp/x.py sed -i 's#^[>.].. ##' /tmp/x.py; xsel -pi >/tmp/x.py nl /tmp/x.py python /tmp/x.py xsel -pi ... copy into the clipboard that can be recalled/pasted by the middle mouse button xsel -ci ... copy 2the clipboard that uses [Ctrl][V] got pasting (and [Ctrl][C/X] for copying/excavating