repeat

Python Repeat Elements in One List Based on Elements from Another

╄→尐↘猪︶ㄣ 提交于 2019-12-01 18:42:48
Given the following lists: a = [0, 5, 1] b = [1, 2, 1] I'd like to repeat each element of [a] by the number of its corresponding position in [b] to produce this: [0, 5, 5, 1] i.e. 0 occurs 1 time, 5 occurs 2 times, and 1 occurs 1 time. In [7]: a = [0, 5, 1] In [8]: b = [1, 2, 1] In [9]: list(itertools.chain(*(itertools.repeat(elem, n) for elem, n in zip(a, b)))) Out[9]: [0, 5, 5, 1] In [10]: b = [2, 3, 4] In [11]: list(itertools.chain(*(itertools.repeat(elem, n) for elem, n in zip(a, b)))) Out[11]: [0, 0, 5, 5, 5, 1, 1, 1, 1] The pieces here are as follows: itertools.repeat(elem, n) - repeat

Strange behaviour of function Sleep() used in repeat until in Delphi

十年热恋 提交于 2019-12-01 18:00:42
问题 I have function which is reaction on button click. When I click on the button it should start repeat and write values form an array and show them in labels on main form. Problem is with function sleep - there is some bug or something, cause when I click on the button it waits quite a long time and then it finaly start the action but very quickly. Let's look at my code. Thx for advices. procedure TForm1.ButtonMereniClick(Sender: TObject); var iterator: Integer; begin iterator := 1; repeat /

Strange behaviour of function Sleep() used in repeat until in Delphi

别来无恙 提交于 2019-12-01 17:42:26
I have function which is reaction on button click. When I click on the button it should start repeat and write values form an array and show them in labels on main form. Problem is with function sleep - there is some bug or something, cause when I click on the button it waits quite a long time and then it finaly start the action but very quickly. Let's look at my code. Thx for advices. procedure TForm1.ButtonMereniClick(Sender: TObject); var iterator: Integer; begin iterator := 1; repeat //write some values stored int arrays to labels on form LabelTeplota.Caption:='Teplota: '+FloatToStr

Stop jQuery from repeating, example attached

随声附和 提交于 2019-12-01 14:19:12
I have to attach a jQuery to an invoice. Sometimes I have to print multiple invoices as once in a batch. When this happens my exact same jQuery appears for every invoice and it runs each time creating extra elements I do not need. Is there a way to have a jQuery that appears more then once only run once when it is the last time it appears in the code? Thanks for any help. Example is below. I have previously posted this and everyone asked to see how I was doing it. I was not sure how to add the code to the post as it said it was too long. Thanks for all your help. You guys are awesome. <table

Finding repeated words in PHP without specifying the word itself

纵然是瞬间 提交于 2019-12-01 09:20:15
I've been thinking about something for a project I want to do, I'm not an advance user and I'm just learning. Do not know if this is possible: Suppose we have 100 html documents containing many tables and text inside them. Question one is: is it possible to analyze all this text and find words repeated and count it?. Yes, It's possible to do with some functions but here's the problem: what if we did not know the words that will gonna find? That is, we would have to tell the code what a word means. Suppose, for example, that one word would be a union of seven characters, the idea would be to

Generate a repeating sequence

允我心安 提交于 2019-12-01 06:49:28
I need to generate a vector of the following format using R: 1:10, 1:10, 11:20, 11:20, ... 121:130, 121:130 Is there an easier way than creating 12 vectors and then repeating each one twice? Is this what you want? unlist(lapply(rep(seq(1, 121, by=10), each=2), function(x) seq(x, x+9))) Also you could do: rep(1:10, 26) + rep(seq(0,120,10), each=20) Another way: x <- matrix(1:130, 10, 13) c(rbind(x, x)) Possible more efficient version: x <- 1:130 dim(x) <- c(10,13) c(rbind(x, x)) Alternatively, you could use a combination of rep and outer , such as: c(outer(1:10,rep(0:12,each=2),function(x,y)10

Finding repeated words in PHP without specifying the word itself

本小妞迷上赌 提交于 2019-12-01 06:37:41
问题 I've been thinking about something for a project I want to do, I'm not an advance user and I'm just learning. Do not know if this is possible: Suppose we have 100 html documents containing many tables and text inside them. Question one is: is it possible to analyze all this text and find words repeated and count it?. Yes, It's possible to do with some functions but here's the problem: what if we did not know the words that will gonna find? That is, we would have to tell the code what a word

Java timer with not-fixed delay

落爺英雄遲暮 提交于 2019-12-01 06:37:18
I need a Timer that basicaly does something every t seconds. But I want to be able to modify the timer period at which the timer repeats the task. I wrote something like this: public Bot() { timer = new Timer(); timer.schedule(new Task(), 1000, moveTime = 1000); } public class Task extends TimerTask { @Override public void run() { System.out.println("Time Passed from last repeat:" + movetime) moveTime += 1000; } So, After 1000ms delay the timer starts and repeats every moveTime ms. The problem is even if I increased movetime by 1000, the timer always runs at initial delay(1000) but the value

Java timer with not-fixed delay

亡梦爱人 提交于 2019-12-01 05:37:07
问题 I need a Timer that basicaly does something every t seconds. But I want to be able to modify the timer period at which the timer repeats the task. I wrote something like this: public Bot() { timer = new Timer(); timer.schedule(new Task(), 1000, moveTime = 1000); } public class Task extends TimerTask { @Override public void run() { System.out.println("Time Passed from last repeat:" + movetime) moveTime += 1000; } So, After 1000ms delay the timer starts and repeats every moveTime ms. The

Fast and Precise Python Repeating Timer

余生长醉 提交于 2019-12-01 04:22:47
I need to send repeating messages from a list quickly and precisely. One list needs to send the messages every 100ms, with a +/- 10ms window. I tried using the code below, but the problem is that the timer waits the 100ms, and then all the computation needs to be done, making the timer fall out of the acceptable window. Simply decreasing the wait is a messy, and unreliable hack. The there is a Lock around the message loop in the event the list gets edited during the loop. Thoughts on how to get python to send messages consistently around 100ms? Thanks from threading import Timer from threading