for-loop

Create subdirectory under each directory containing a file

假如想象 提交于 2020-03-23 12:01:35
问题 I have a large number of photos that are contained in over 100 directories. These are all pre-installation photos. I would like to keep the existing directory structure but add a \pre and \post directory in any directory that contains a .jpg photo. I dont want a subdirectory created if a given directory only contains other directories but not files For testing , I have a single .jpg in c:\temp\one\two\three. I ran this command in c:\temp: FOR /R c:\temp %G IN (*.jpg) DO mkdir pre However, it

How to save output of for loop in separate csv files?

时间秒杀一切 提交于 2020-03-21 06:22:52
问题 As an image and code that I attached below, I have a set of transaction data and each row has its industry name. reproducible example data: structure(list(Date = c(1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201, 1201), Sex = c("Male", "Male", "Female", "Male", "Male", "Female", "Male", "Female", "Male", "Male"), Age = c(10, 15, 20, 15, 40, 50, 20, 30, 50, 20), City = c("Pheonix", "Atlanta", "Las Vegas", "Las Vegas", "Denver", "Pheonix", "Atlanta", "Las Vegas", "Las Vegas", "Minneapolis"

What happened when `pop`-ing an element while `for` looping a list [duplicate]

怎甘沉沦 提交于 2020-03-18 09:20:57
问题 This question already has answers here : Modifying list while iterating [duplicate] (7 answers) Closed 6 years ago . Code: arr = [ i for i in xrange(10) ] for i in arr: if i in arr: print i arr.pop(0) print arr And the output: $ python2.7 ts.py 0 2 4 6 8 [5, 6, 7, 8, 9] Why is this the result? Shouldn't it be [] ? 回答1: Updating a Sequence while Iterating has some unexpected results, which is why it is never recommended. The following graphic depicts how the variable i changes every time you

What happened when `pop`-ing an element while `for` looping a list [duplicate]

久未见 提交于 2020-03-18 09:20:33
问题 This question already has answers here : Modifying list while iterating [duplicate] (7 answers) Closed 6 years ago . Code: arr = [ i for i in xrange(10) ] for i in arr: if i in arr: print i arr.pop(0) print arr And the output: $ python2.7 ts.py 0 2 4 6 8 [5, 6, 7, 8, 9] Why is this the result? Shouldn't it be [] ? 回答1: Updating a Sequence while Iterating has some unexpected results, which is why it is never recommended. The following graphic depicts how the variable i changes every time you

Performance of Enumerable.Range vs for loop

流过昼夜 提交于 2020-03-18 07:00:31
问题 I wondered what the performance overhead is of using Enumerable.Range was against using a foreach loop. For example: var stringArray = Enumerable.Range(0, 4).Select(i => string.Empty).ToArray(); VS. var stringArray = new string[4]; for (int i = 0; i < formatted.Length; i++) { stringArray[i] = string.Empty; } I spotted these question: Why is Enumerable.Range faster than a direct yield loop? Enumerable.Range implementation Thoughts on foreach with Enumerable.Range vs traditional for loop But I

How do I make my for loop properly calculate means over time?

大憨熊 提交于 2020-03-16 08:46:53
问题 I have data on all the NCAA basketball games that have occurred since 2003. I am trying to implement a for loop that will calculate the average of a number of stats for each time at a point in time. Here is my for loop: library(data.table) roll_season_team_stats <- NULL for (i in 0:max(stats_DT$DayNum)) { stats <- stats_DT[DayNum < i] roll_stats <- dcast(stats_DT, TeamID+Season~.,fun=mean,na.rm=T,value.var = c('FGM', 'FGA', 'FGM3', 'FGA3', 'FTM', 'FTA', 'OR', 'DR', 'TO')) roll_stats$DayNum <-

In R how do I find whether an integer is divisible by a number?

心已入冬 提交于 2020-03-15 06:35:31
问题 Sorry for the inexperience, I'm a beginning coder in R For example: If I were to make a FOR loop by chance and I have a collection of integers 1 to 100 (1:100), what would be the proper format to ensure that would print the numbers that are divisible by another number. In this case, 5 being the number divisible. I hear that using modulo would help in this instance %% This is what I think I should have. For (x in 1:100) { x%%5 == y } print(y) 回答1: for (x in 1:100) { if (x%%5 == 0) { print(x) }

How to print the list in 'for' loop using .format() in Python?

谁都会走 提交于 2020-03-14 05:18:12
问题 I'm a newbie to Python. I'm writing a very simple piece of code to print the contents of a list using 'for' loop with .format() and I want the output as below, but I'm getting this error: names = ['David', 'Peter', 'Michael', 'John', 'Bob'] for i in names: print("{}.{}".format(i, names[i])) print("{}.{}".format(i,breakfastMenu[i])) TypeError: list indices must be integers or slices, not str Expected output I want: 1. David 2. Peter 3. Michael 4. John 5. Bob Can someone please help me to get

How to print the list in 'for' loop using .format() in Python?

爷,独闯天下 提交于 2020-03-14 05:17:09
问题 I'm a newbie to Python. I'm writing a very simple piece of code to print the contents of a list using 'for' loop with .format() and I want the output as below, but I'm getting this error: names = ['David', 'Peter', 'Michael', 'John', 'Bob'] for i in names: print("{}.{}".format(i, names[i])) print("{}.{}".format(i,breakfastMenu[i])) TypeError: list indices must be integers or slices, not str Expected output I want: 1. David 2. Peter 3. Michael 4. John 5. Bob Can someone please help me to get

Looping and adding together the values generated

雨燕双飞 提交于 2020-03-06 07:32:24
问题 I have just started learning javascript, and I've hit a bit of a roadblock whilst designing the logic behind a 10 pin bowling scorecard. I would be really grateful if someone could help me figure out how, instead of my messy code below for the totalScore function, I could use a for loop that will add all of the values together. The code that I have so far is as follows. Thank you in advance! function Game() { this.scorecard = [] }; Game.prototype.add = function(frame) { this.scorecard.push