for-loop

Split lists and tuples in Python

ε祈祈猫儿з 提交于 2020-02-07 02:36:30
问题 I have a simple question. I have list, or a tuple, and I want to split it into many lists (or tuples) that contain the same elements. I'll try to be more clear using an example: (1,1,2,2,3,3,4) --> (1,1),(2,2),(3,3),(4,) (1,2,3,3,3,3) --> (1,),(2,),(3,3,3,3) [2,2,3,3,2,3] --> [2,2],[3,3],[2],[3] How can I do? I know that tuples and lists do not have the attribute "split" so i thought that i could turn them into strings before. This is what i tried: def splitt(l) x=str(l) for i in range (len(x

Batch write text from file into local variable error [closed]

寵の児 提交于 2020-02-07 01:59:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 days ago . My scenario is the following: I have a huge file with 700.000+ lines. I have to work with this, I name this file now trc.txt The structure of each line of this file is like so: 20958 191014 07:43:57.08 CCComRPC DCMSGCFW_E PID:00000864.00001F40 Data:23 < PREP_FIXED::Process 0 I have a seconde file, I call it

Extract digits from a long number in C

拈花ヽ惹草 提交于 2020-02-06 07:58:07
问题 I'm trying to extract the digits from a number n , with: 00000000000 ≤ n ≤ 99999999999 using the following code: #include <stdio.h> int main() { int N; int power=1; scanf("%d",&N); while(N>power) power*=10; power/=10; while(N != 0) { int digit = N/power; printf("%d\n", digit); if(digit!=0) N=N-digit*power; if(power!=1) power/=10; } return 0; } It works well for a range of values, but for an 11 digit number, I get an error. Any tips on how to fix it to handle the n range? 来源: https:/

Extract digits from a long number in C

守給你的承諾、 提交于 2020-02-06 07:57:30
问题 I'm trying to extract the digits from a number n , with: 00000000000 ≤ n ≤ 99999999999 using the following code: #include <stdio.h> int main() { int N; int power=1; scanf("%d",&N); while(N>power) power*=10; power/=10; while(N != 0) { int digit = N/power; printf("%d\n", digit); if(digit!=0) N=N-digit*power; if(power!=1) power/=10; } return 0; } It works well for a range of values, but for an 11 digit number, I get an error. Any tips on how to fix it to handle the n range? 来源: https:/

How do i access ArrayList that is in another class using for each loop

蓝咒 提交于 2020-02-06 07:55:47
问题 How do I use ArrayList in Message() method loop? I want to access the arraylist and get atributes of the person to form final message in registration process. package sample; import java.util.ArrayList; public class PersonRegister { private static ArrayList<Person> regiter = new ArrayList<>(); public void regitration (String name, String email, String phonennr, int year, int monht, int day, int age){ Person onePerson = new Person(name,email,phonennr, year,monht,day,age); regiter.add(onePerson

How to generate unique random numbers (that don't repeat)?

喜欢而已 提交于 2020-02-06 06:48:16
问题 I'm trying to write a code that randomly chooses numbers and adds them to the list random_numbers , but if a random number was already generated, the code detects that and replaces the number with another, until every number is different. import random random_numbers = [] for x in range(11): This part generates a random integer and appends it to the list random_numbers : random_numbers.append('[q' + str(random.randint(1, 11)) + ']') This part is supposed to iterate over the list and check if

How to generate unique random numbers (that don't repeat)?

久未见 提交于 2020-02-06 06:45:34
问题 I'm trying to write a code that randomly chooses numbers and adds them to the list random_numbers , but if a random number was already generated, the code detects that and replaces the number with another, until every number is different. import random random_numbers = [] for x in range(11): This part generates a random integer and appends it to the list random_numbers : random_numbers.append('[q' + str(random.randint(1, 11)) + ']') This part is supposed to iterate over the list and check if

Auth.User.None when rendering a ManyToManyField

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-05 06:36:06
问题 I am trying to render a ManyToManyField from a model that render a list of hotels with staff that belong to each hotel. I am trying to display in the template the users that are inside the current hotel being shown but I get an error auth.User.None my template {% for Hotel in object_list %} {{ Hotel.collaborateurs }} {% endfor %} My models.py class Hotel(models.Model): collaborateurs = models.ManyToManyField(User, verbose_name="Liste des collaborateurs autorisés") (....) Thanks Edit ; I am

For loop Increment with a step not working

自作多情 提交于 2020-02-05 04:32:05
问题 The following Go program fails to compile package main import ( "fmt" ) func main() { var celcius int for i := 0; i <= 300; i + 20 { celcius = 5 * (i - 32) / 9 fmt.Printf("%d \t %d\t \n", i, celcius) } } The Error message is "i + 20 evaluated but not used" . How to give a step increment in golang for loop 回答1: The compiler is complaining that the result of the expression i + 20 is not used. One fix is to assign result to i : for i := 0; i <= 300; i = i + 20 { A shorter and more idiomatic

Clean mathematical notation of a for-loop

拟墨画扇 提交于 2020-02-03 19:02:02
问题 I am sorry if this doesn't really belong here but I'm looking for a way to describe the mathematical background of my code. Using numpy I sum two more dimensional arrays: a.shape = (10, 5, 2) b.shape = (5, 2) c = a + b c.shape = (10, 5, 2) Is there a pure mathematical notation for this (so WITHOUT indroducing for-loops or numpy conventions in my text)? What I'm trying to avoid is to have to write something like this: c_{1, y, z} = a_{1, y, z} + b_{y, z} c_{2, y, z} = a_{2, y, z} + b_{y, z} ..