Can anyone explain the internal working of this complete program, like what’s happening after i reaches the last item of the list, what happens after the 3rd line of output? 🙂 list1 = [1,2,4,5] for i,x in enumerate(list1): for y,z in enumerate(list1[i+1:],i+1): print(y,z) Output: 1 2 2 4 3 5 2 4 3 5 3 ..
Category : for-loop
I’m trying to make a program that calculates the sum of the first N odd numbers. where N is the number of the first odd numbers (e.g. N=4, then the first odds are 1,3,5,7) it should output the odd numbers. is the code correct? (given that it needs to be in a loop) or is ..
I am looking for a piece of code that will create a list of x number of integers between 1 and 100,000 with only up to 10 duplicates per integer. This is supposed to be implemented using Python. So far I have this: randomlist = [] for i in range(0,100000): n = random.randint(1,100) randomlist.append(n) print(randomlist) ..
x = e[[‘a’,’b’,’c’,’d’]] step = 110 x_pieces = [x[i:i+step] for i in range(0, len(x), step)] So, I have a data frame e and a, b ,c , d are corresponding columns in data frame. Here, I am diving the data in steps of 110. But, I would like to specify the step size as a ..
I have a number of variables that I would like to create in an automated way based on 2 lists, but unsure how to do so. The objective is unique, but would help me immensely. list 1 is a list of names – subqueries = [‘name’, ‘name2’, ‘name3’] list 2 is generated from a for ..
I am working with 4D data set, where I have a nested for loop (4 loops). The for loop works, but it takes a while to load, ~5 minutes. I am trying to write this properly with list comprehension instead, but I am getting confused on exactly how to do this given my nested loops: ..
when given array = [0.771, 0.812, 0.812, 0.847, 0.847, 0.847, 0.849, 0.847, 0.887, 0.862, 0.863, 0.892, 0.874, 0.874, 0.899, 0.945,0.910, 0.872, 0.887, 0.874, 0.872, 0.896, 0.896, 0.860, 0.912, 0.913, 0.912, 0.871, 0.871, 0.865, 0.899, 0.866] I want to find a maximum value by using sliding window algorithm.(Not by using np.max()) n = len(array) k = ..
I have this column of dataframe as follows: Mass Market Paperback,– 1 Oct 1986 – Paperback,– Import, 26 Apr 2018 – Paperback,– 17 Mar 2011 – Paperback,– 2016 – Paperback,– 26 Dec 2011 I want to extract months and years from this list it is a long list. I have executed the following program: def ..
I have a list of values that I would like to loop through and insert into a """ string statement. But am new to for loops and not exactly sure the best approach to insert list values efficiently. I have a list – subqueries = [‘name’,’name2′,’name3′] And a string statement – """SELECT * FROM <insert ..
I have a python script for the scrapping site, I need to scrap a few info(name, price, links, ID) this info will be put in MongoDB. But I have a problem with my scrap function. It returns to me a blank list. Can you help me please with this? Sorry for my English and thank ..
Recent Comments