iteration

how to Iterate through an arrayList of object and find duplicates in object properties? [closed]

≡放荡痞女 提交于 2020-01-04 18:40:06
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have the following class: class A { ArrayList<String> s = new ArrayList<>(); double d = Double.MAX_VALUE; } I've an arrayList of

How to iterate over cms plugin instances from a page in a Django template?

馋奶兔 提交于 2020-01-04 18:32:13
问题 I want to display a list of YouTube videos and let my user edit this list. I thought of doing it like this: Make a template where this will be displayed. In this template do something like <ul>{% for plugin in page %}<li>plugin</li>{% endfor %}</ul> . Make a youtube_videos placeholder and configure it to be limited to only that type of plugin. But I don't know how to make this iteration over the plugin instances in the current page in the template. I didn't see anything about this in django

How to iterate over cms plugin instances from a page in a Django template?

和自甴很熟 提交于 2020-01-04 18:32:08
问题 I want to display a list of YouTube videos and let my user edit this list. I thought of doing it like this: Make a template where this will be displayed. In this template do something like <ul>{% for plugin in page %}<li>plugin</li>{% endfor %}</ul> . Make a youtube_videos placeholder and configure it to be limited to only that type of plugin. But I don't know how to make this iteration over the plugin instances in the current page in the template. I didn't see anything about this in django

Iterating through a vector of stucts's members with pointers and offsets

自作多情 提交于 2020-01-03 20:56:56
问题 I am trying to optimize a piece of code by not pointer chasing, as much as I currently am. I want to create a constant offset to add to a stored pointer to get to the next data entry, see below code. However, the data is sitting side a class or struct, containing different data types. So I get the correct behavior in the below code snippet, ie the output is 1, 2, 3. #include <iostream> #include <vector> // knows nothing about foo class Readfoo { private: int offset; double* pdouble; public:

Is iteration order over the different Collection views of a given Map guaranteed to be consistent?

泪湿孤枕 提交于 2020-01-03 15:03:11
问题 For a given type of Map , are there any guarantees that iterating over the Collection views returned by the keySet , values and entries methods are iterated in the same order? Background: I'm wondering whether transforming public static void doSomethingForEachEntry(Map<String, Integer> someMap) { for (String key : someMap.keySet()) { doSomething(someMap.get(key)); } } to public static void doSomethingForEachEntry(Map<String, Integer> someMap) { for (Integer value : someMap.values()) {

Speeding up a numpy loop in python?

两盒软妹~` 提交于 2020-01-03 10:21:32
问题 Consider the following code using numpy arrays which is very slow : # Intersection of an octree and a trajectory def intersection(octree, trajectory): # Initialize numpy arrays ox = octree.get("x") oy = octree.get("y") oz = octree.get("z") oe = octree.get("extent")/2 tx = trajectory.get("x") ty = trajectory.get("y") tz = trajectory.get("z") result = np.zeros(np.size(ox)) # Loop over elements for i in range(0, np.size(tx)): for j in range(0, np.size(ox)): if (tx[i] > ox[j]-oe[j] and tx[i] < ox

Retrieving total number of words with 2 or more letters in a document using python

六月ゝ 毕业季﹏ 提交于 2020-01-03 06:47:17
问题 I have a small Python script that calculates the top 10 most frequent words, 10 most infrequent words and the total number of words in a .txt document. According to the assignment, a word is defined as 2 letters or more. I have the 10 most frequent and the 10 most infrequent words printing fine, however when I attempt to print the total number of words in the document it prints the total number of all the words, including the single letter words (such as "a"). How can I get the total number

Way to go from recursion to iteration

我只是一个虾纸丫 提交于 2020-01-03 05:55:11
问题 I've used recursion quite a lot on my many years of programming to solve simple problems, but I'm fully aware that sometimes you need iteration due to memory/speed problems. So, sometime in the very far past I went to try and find if there existed any "pattern" or text-book way of transforming a common recursion approach to iteration and found nothing. Or at least nothing that I can remember it would help. Are there general rules? Is there a "pattern"? 回答1: Usually, I replace a recursive

C# Efficient way to iterate over excel worksheet

て烟熏妆下的殇ゞ 提交于 2020-01-02 10:26:14
问题 I have the following code: string result = ""; for(int i=2; i<=excelRange.Rows.Count; i++) { result += excelRange.Cells[i, 2].Value2; } For an excel file with a couple hundred entries this takes 5 seconds. Is there a more efficient way, perhaps? I only want the values from B2 to Bn. 回答1: Yes, there is a more efficient way. Create a range that exactly matches the cells that you really need. Get the Value2 property of this range. The result will be an array type. Iterate through the array The

Modifying dictionary values while iterating with dict.values() or dict.itervalues()

夙愿已清 提交于 2020-01-02 07:26:13
问题 I have a dicionary that is initialized like so: tab = {'Mike': 0, 'Chad': 15, 'Taylor': 2} I want to be able to add integers to each value in the dictionary. For example, after adding 5, the dictionary should look like this: {'Mike': 5, 'Chad': 20, 'Taylor': 7} It seems as if this can be done with a couple of lines of code but I can't figure it out. I've tried a for loop: for k in tab.itervalues(): k = k + 5 I run this code and then print out the dictionary: tab = {'Mike': 0, 'Chad': 15,