Python3 print formatting - printing

I want to format the output from print function.
def main():
print('1 2 3 4 5'*7)
# Write code here
main()
Required Output:
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Obtained Output:
1 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 51 2 3 4 5
How do I make print function in Python3 to perform this job?

You can set the separator to be a linebreak.
print(*7*('1 2 3 4 5',), sep='\n')
Equivalently, you can add the linebreak at the end of the string and remove the end linebreak from print.
print(7*'1 2 3 4 5\n', end='')

Try this:
print('1 2 3 4 5\n'*7)

Related

How To Skip Down by 1 Row/Cell The Formula Output and Remove The Last Sequential Output Before 1's Google Sheets?

I've got these 3 groups of data in range F2:G22 as below
(3 groups as minimal example, in reality many thousands of groups, and recurrent similar datasets expected in the future):
I need to number each group's rows sequentially, starting over at 1 at each new group.
The expected result would be like in range E1:E22.
I tried the following formula n cell C2 , then in cell D3:
=INDEX(IF(A2:A22="",COUNTIFS(B2:B22&A2:A22, B2:B22&A2:A22, ROW(B2:B22), "<="&ROW(B2:B22)),1))
In C2:
In D3:
That fixed partially the sequence issue, but there's still 2 issues I can't find remedy for.
1st remaining issue:
I'd prefer not having to manually do the C2 to D3 step each time I get new similar data (but would accomodate if there's no simple solution to this issue).
Is there a simple way to modify the formula to make it output the correct sequencing from C2 ?
2nd remaining issue:
At rows 7, 14 and 23 there still remain unecessary ending numbering for these intermediary rows in D7 , D14 , and D23:
I could only think of an extra manual step of filtering out the non-blank rows in Column A to fix this 2nd issue (i.e. Highlighting Column A > Data tab > Create Filter > Untick all > Tick Blanks > Copy All > Paste In new Sheet).
But would there be a way to do it in the same formula? I'm not seeing the way to add the proper filter or using another method in the formula.
Any help is greatly appreciated.
EDIT (Sorry for Forgotten Sample):
Formula Input A
Formula Input B
Formula Output 1
Formula Output 2
EXPECTED RESULT
rockinfreakshow
ztiaa
DATA
DATA BY GROUP
7
1
1
7
7
2
1
1
1
2
Element-1
Group-1
7
3
2
2
2
3
Element-2
Group-1
7
4
3
3
3
4
Element-3
Group-1
7
5
4
4
4
5
Element-4
Group-1
8
1
5
6
8
8
2
1
1
1
7
Element-1
Group-2
8
3
2
2
2
8
Element-2
Group-2
8
4
3
3
3
9
Element-3
Group-2
8
5
4
4
4
10
Element-4
Group-2
8
6
5
5
5
11
Element-5
Group-2
8
7
6
6
6
12
Element-6
Group-2
9
1
7
13
9
9
2
1
1
1
14
Element-1
Group-3
9
3
2
2
2
15
Element-2
Group-3
9
4
3
3
3
16
Element-3
Group-3
9
5
4
4
4
17
Element-4
Group-3
9
6
5
5
5
18
Element-5
Group-3
9
7
6
6
6
19
Element-6
Group-3
9
8
7
7
7
20
Element-7
Group-3
9
9
8
8
8
21
Element-8
Group-3
9
Can you try:
=INDEX(LAMBDA(y,z,
IF(LEN(z),COUNTIFS(y,y,ROW(z),"<="&ROW(z)),))
(LOOKUP(ROW(G2:G),FILTER(ROW(G2:G),BYROW(G2:G,LAMBDA(z,IF(z<>OFFSET(z,-1,0),row(z),0))))),G2:G))
You can simply use SCAN.
=SCAN(,G2:G,LAMBDA(a,c,IF(c="",,a+1)))
Sample sheet

Google Sheets: How can I FILTER a range based on a value in the previous row?

I'm working with a golf data set and I'm looking for a way to filter holes based on the result of a previous hole. In the end, I want this range to be able to get the average score of the golfer following a bogey or worse.
I've made a few attempts with FILTER(), OFFSET(), and even INDIRECT(), but I can't figure out how to properly use values from a different row as the condition for my filter.
=FILTER(A2:D10, OFFSET(D2:D10, -1, 0) >= 1, ROW(D2:D10) <> 2) (errors with "FILTER has mismatched range sizes.")
=INDIRECT("D"&FILTER(ROW(A2:D10)+1, D2:D10 >= 1, ROW(D2:D10) <> 2)) (only returns the first value)
Sample Data:
A B C D
-----------------------------
1 | Hole Par Score ScoreDiff
2 | 1 4 5 1
3 | 2 4 4 0
4 | 3 4 3 -1
5 | 4 5 6 1
6 | 5 3 3 0
7 | 6 5 6 1
8 | 7 3 4 1
9 | 8 4 5 1
10 | 9 4 4 0
Desired outcome: only the holes directly following a bogey or worse (where ScoreDiff >= 1)
A B C D
-----------------------------
1 | 2 4 4 0
2 | 5 3 3 0
3 | 7 3 4 1
4 | 8 4 5 1
5 | 9 4 4 0
Simpler option:
=FILTER(A3:D11,D2:D10>=1)
try:
=FILTER(A2:D10, {""; D2:D9} >= 1, ROW(D2:D10) <> 2)

Why iOS audio capture callback time interval is not smooth?

I writing my iOS app to record audio.
I called session.setPreferredIOBufferDuration(0.001) to set the duration, and recorded the intervals between two callbacks.
This is data of my iPhone 8:
max = 198 avg = 2.75314 min = 0
======================================================
4 2 2 3 5 3 1 3 6 1
2 2 6 0 5 3 1 3 3 5
1 3 3 2 3 5 1 3 3 3
3 4 1 4 3 2 4 2 3 3
3 3 3 3 2 3 3 3 5 1
3 2 3 3 3 3 3 5 1 3
3 3 3 3 3 3 4 1 3 3
3 3 3 2 3 4 2 3 3 3
3 4 5 0 2 3 3 3 3 3
3 3 3 3 2 3 4 2 3 3
3 3 3 3 3 3 4 2 2 4
3 2 4 2 3 2 4 3 4 2
2 3 3 3 3 2 4 3 5 1
2 4 2 3 2 3 4 3 3 2
4 5 1 2 3 4 2 4 1 3
3 3 3 5 2 2 2 4 2 3
3 3 3 6 0 3 3 3 2 3
3 3 4 2 3 3 2 3 3 3
3 3 3 3 5 1 2 3 3 3
3 3 4 4 1 2 3 3 4 2
3 3 3 3 3 2 3 6 0 3
3 3 4 2 3 3 3 2 5 1
And this is data of my iPhone 7:
max = 246 avg = 2.59249 min = 0
======================================================
3 2 3 2 3 3 5 2 2 3
3 3 3 4 2 2 3 3 3 3
221 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 2 0 0 0
0 0 0 0 0 0 0 1 7 1
1 3 2 3 3 3 3 2 4 4
1 3 4 2 3 3 5 4 0 2
3 5 2 3 2 3 3 4 2 3
2 6 0 4 2 3 3 3 4 3
1 3 3 3 5 3 1 3 3 2
as you see, the max interval is far away from 1ms I set to AudioSession.
and huge numbers form iPhone 7 is appeared much often.
Why iOS don't call my callback smoothly? Can I do any thing, such as set some preference, to get more smooth data?
Thank you.
1) The preferred buffer duration is only a suggestion to the OS. Mostly followed, depending on the device models hardware capabilities. 256 frames is supported on all current iOS devices. Smaller numbers may work on only some newer iOS device models. But iOS devices are free to use different buffer sizes (thus durations) for each audio unit callback. And sometimes does (due to power management, audio route changes, hardware start/stop issues, and etc.)
2) The interval between the starts of Audio Unit buffer callbacks is extremely consistent. Highly variable latency issues are usually the result of the code inside the callbacks taking too long. Did you follow all the audio context real-time rules? (no long operations, no Swift, no Objective C messaging, no locks, no memory management, no file reads or writes, no UI calls, and etc. ?)

Xcode: Random Contextless Hexadecimal Output to Console

I have an iOS app developed in Xcode. When running my app in the simulator, I'm getting some random hexadecimal output in the console log when navigating to one particular view controller (example below). It does not happen when navigating to other controllers, and I don't see anything jumping out at me that I'm doing differently in this instance, and there are no apparent effects in the simulator of anything being wrong.
Has anyone seen this, can you lend any direction as to what is causing it, or at the very least tell if this is cause for alarm?
The output does not have a timestamp or my app name as a prefix like an NSLog output such as 2020-03-17 14:50:54.387749-0400 AppName. The output is consistent every time with the same information being logged.
0000000A: 0100 4 4 800
00000016: 0101 4 4 800
00000022: 0102 3 6 110
0000002E: 011A 5 8 116
0000003A: 011B 5 8 124
00000046: 0128 3 2 2
00000052: 0131 2 12 132
0000005E: 0132 2 20 144
000000A6: 0100 4 4 256
000000B2: 0101 4 4 256
000000BE: 0102 3 6 266
000000CA: 0103 3 2 6
000000D6: 0106 3 2 6
000000E2: 0115 3 2 3
000000EE: 0201 4 4 272
000000FA: 0202 4 4 4506
0000000A: 0100 4 4 800
00000016: 0101 4 4 800
00000022: 0102 3 6 110
0000002E: 011A 5 8 116
0000003A: 011B 5 8 124
00000046: 0128 3 2 2
00000052: 0131 2 12 132
0000005E: 0132 2 20 144
000000A6: 0100 4 4 256
000000B2: 0101 4 4 256
000000BE: 0102 3 6 266
000000CA: 0103 3 2 6
000000D6: 0106 3 2 6
000000E2: 0115 3 2 3
000000EE: 0201 4 4 272
000000FA: 0202 4 4 4506
0000000A: 0100 4 4 800
00000016: 0101 4 4 800
00000022: 0102 3 6 110
0000002E: 011A 5 8 116
0000003A: 011B 5 8 124
00000046: 0128 3 2 2
00000052: 0131 2 12 132
0000005E: 0132 2 20 144
000000A6: 0100 4 4 256
000000B2: 0101 4 4 256
000000BE: 0102 3 6 266
000000CA: 0103 3 2 6
000000D6: 0106 3 2 6
000000E2: 0115 3 2 3
000000EE: 0201 4 4 272
000000FA: 0202 4 4 4506
0000000A: 0100 4 4 800
00000016: 0101 4 4 800
00000022: 0102 3 6 110
0000002E: 011A 5 8 116
0000003A: 011B 5 8 124
00000046: 0128 3 2 2
00000052: 0131 2 12 132
0000005E: 0132 2 20 144
000000A6: 0100 4 4 256
000000B2: 0101 4 4 256
000000BE: 0102 3 6 266
000000CA: 0103 3 2 6
000000D6: 0106 3 2 6
000000E2: 0115 3 2 3
000000EE: 0201 4 4 272
000000FA: 0202 4 4 4506

I want to exit the reccursion when i input just a newline in erlang

-module(solution).
-export([main/0]).
do_it(_X,0)->
true;
do_it(X,K) when K>0->
io:format("~p~n",[X]),
do_it(X,K-1).
kis(T)->
{ok,[K]}=io:fread("","~d"),
do_it(K,T),
kis(T).
main()->
{ok,[K]}=io:fread("","~d"),
kis(K).
Input (stdin)
2
1
2
3
4
5
6
7
8
9
10
MY Output (stdout)
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
{"init terminating in do_boot",{{badmatch,eof},[{solution,kis,1,[{file,"/run-yvsveha40GAvIJDSfd6N/solution.erl"},{line,9}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
Expected Output
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
You can use something like this:
kis(T) ->
case io:fread("","~d") of
{ok,[K]} -> do_it(K,T), kis(T);
_ -> ok
end.
main()->
case io:fread("","~d") of
{ok,[K]} -> kis(K);
_ -> ok
end.

Resources