Dear All, I have a very long list of values as follow (43, 560) (516, 1533) (1316, 3047) (520, 1528) (3563, 1316) (45, 557) (3562, 1312) (2686, 1964) (2424, 3340) (3559, 1317) (50, 561) (2427, 3336) (1313, 3046) (3562, 1313) (3559, 1318) (2689, 1962) (2429, 3339) (3721, 2585) (1317, 3048) I would like to group values within a certain tolerance. Say I set tolerance to 3, my 1st and 6th results ((43, 560) (45, 557)) should be grouped together in an average value: (44, 558.5). What approach would be the best? I really don't know where to start from. The …

Member Avatar
Member Avatar
+0 forum 7

The Swift computer language is the brainchild of a number of Apple associates. In my humble opinion it shows some nice features, but also some warts. Part 1 (constants, variables, strings, tuples, arrays) explores a number of the features to give you a taste of the language. I hope I can follow this soon with part 2 (dictionaries, loops, if/else, switch/case,.functions, classes) Even if you don't have an Apple computer, you can educate yourself using the Swift computer language. Just go onto the **Swift online playground** at **swiftstub.com** and start typing Swift code, enjoy the experience! Note: Xcode 7.0 came …

Member Avatar
Member Avatar
+2 forum 27

Hi guys, I have written a program which currently accumalates different pairs and their frequency from an excel spreadsheet. (1280 pairs) Want I want to achieve is from the top 20/30 pairs, if I can find pairs that link e.g. Pair 1 [1,33] and Pair 100 [1,232] so i would expect that to be a link. With that link i want to be able to merge it so the the value becomes e.g. [33,1,232] before continue to find any more. My find outcome should be a set of 10 numbers which are linked together by thier pairs. Anyone one have …

Member Avatar
Member Avatar
+0 forum 3

How to use two models in a view using Tuple and view model and what is there diffences?

Member Avatar
Member Avatar
+0 forum 3

This is my code: class MyTime: def __init__(self, hrs=0, mins=0, secs=0): self.hours = hrs self.minutes = mins self.seconds = secs if self.seconds >= 60: self.minutes += self.seconds // 60 self.seconds = self.seconds % 60 if self.minutes >= 60: self.hours += self.minutes // 60 self.minutes = self.minutes % 60 if self.hours >= 24: self.hours = self.hours % 24 def get_sec(self): return (self.hours * 60 + self.minutes) * 60 + self.seconds def __str__(self): return "{:02d}:{:02d}:{:02d}".\ format(self.hours, self.minutes, self.seconds) def between(self, t1, t2): return (t1.get_sec()) <= (self.get_sec()) and (self.get_sec()) <= (t2.get_sec()) t1 = (9, 59, 59) print("t1 =", t1) t2 = (10, 0, …

Member Avatar
Member Avatar
+0 forum 4

Don’t know if this is ever been done before, or even if it is a good way to do it. I’ll just await your comments if any. What I mostly found on the web is that if you want to define a polynomial you need to have an array containing the coefficients. The place of the coefficient in the array determines the power of the unknown, you have to include a 0(zero) in the array for the powers that are not in your polynomial. So I tried to do it using a list of tuples, with one element containing the …

Member Avatar
+0 forum 0

Hello everyone! I would like your help regarding this: I have a tuple vector which i must iterate through, and accessing the vector data to decide wether to erase or not the current vector element. My code : typedef tuple <int, CString, int, int> pc_data; vector <pc_data> pc_vec; //Assume that pc_vec is filled with elements somewhere here... //This code is not working. //Exception : vector subject out of range because of the size dynamically changing i suppose for (int i=0; i<num_of_pcs; i++) { if(std::get<2>(pc_vec[i])==0) pc_vec.erase(pc_vec.begin()+i); } //second try //No exception here but the dynamic size of the vector again won't …

Member Avatar
Member Avatar
+0 forum 6

I have a data set like this data=[{u'a': u'D', u'b': 100.0, u'c': 201L, u'd': datetime.datetime(2007, 12, 29, 0, 0), u'e': datetime.datetime(2008, 1, 1, 6, 27, 41)},{u'a': u'W', u'b': 100.0, u'c': 201L, u'd': datetime.datetime(2007, 12, 29, 0, 0), u'e': datetime.datetime(2008, 2, 4, 6, 27, 41)},{u'a': u'W', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 1, 1, 4, 20, 44)},{u'a': u'D', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 3, 11, 6, 27, 41)},{u'a': u'D', u'b': 100.0, u'c': 202L, u'd': datetime.datetime(2007, 12, 30, 0, 0), u'e': datetime.datetime(2008, 5, 8, 11, 2, 41)},{u'a': u'D', u'b': …

Member Avatar
Member Avatar
+0 forum 1

I wrote out a test for a Complex class on python but I'm getting an error. Here's what I have: class Complex: def __init__(self, real=0, imaginary=0): self._r=real self._i=imaginary def __add__ (self, other): return Complex((self._r + other._r), (self._i + other._i)) def __sub__ (self, other): return Complex((self._r - other._r), (self._i - other._i)) def __mul__ (self, other): return Complex((self._r * other._r - self._i * other._i), (self._r * other._i + self._i * other._r)) def __truediv__ (self, other): return Complex(((self._r * other._r + self._i * other._i)) / (self._i**2 + other._i**2), ((self._r * other._i - other._r * self._i)) / (self._i**2 + other._i**2)) def __str__ (self): if …

Member Avatar
Member Avatar
+0 forum 3

Dear Friends, I have a sequence of two values as the following: 00001.doc d:\pathtofile\image50.jpg 00002.doc d:\pathtofile\image38.jpg 00003.doc d:\pathtofile\image40.jpg ... I would like to add the values to a list, sort the list by second value and rename the first value accordingly. For example, the following steps: Step 1 '00002.doc', 'd:\pathtofile\image38.jpg' '00003.doc', 'd:\pathtofile\image40.jpg' '00001.doc', 'd:\pathtofile\image50.jpg' Step 2 'a00001.doc', 'd:\pathtofile\image38.jpg' 'a00002.doc', 'd:\pathtofile\image40.jpg' 'a00003.doc', 'd:\pathtofile\image50.jpg' The pathtofile is always the same, so I will not need (probably) to break it and extract the filename. Thank you for your help. G.

Member Avatar
Member Avatar
+0 forum 2

Dear friends, sorry for my ignorance about python containers but I have the need to store (and access) 4 different values per file in folder, namely the filename (with its path) and 3 other values (string or None). When I access the database, I will need to know the 3 values of one specific file. I am exploring different solutions, but since I am not that expert, I cannot manage to find a good one. Should a list of tuple work well? Something like mylist=[] for file in glob.glob(inputpath+"\\*.txt"): mylist.append([file, value1, value2, value3]) I was even thinking to save the …

Member Avatar
Member Avatar
+0 forum 6

hi guys. our teacher posted a bonus a while ago that has me scratching my head. he still will not show us how to do it. i was wondering if u guys could crack it. here are the instructions: [Click Here](http://prntscr.com/inqqz) there are also **2 ** files to supplement: **.txt** ocean,4 -500, -360 -500, 360 500, 360 500,-360 shallow, 16 -460, -140 -460, -140 -460, 165 -250, 315 50, 265 200, 215 400, 215 425, 150 450, -45 250, -145 200, -245 -100, -245 -150, -170 -200, -95 -250, -95 -300, -140 sand, 29 -400, -90 -450, 60 -400, 110 …

Member Avatar
Member Avatar
+0 forum 2

so im trying to make it so that pressing enter without inputting any value, will break the loop, however, an empty string can be used because of [ICODE]for i in range(len(x_str_array)): x[i] = int(x_str_array[i]) bit.[/ICODE] [CODE] 'Exercise 7.3' # modified program from exercise 7.2 a=1 z="" while x !=z: x_str = raw_input('Enter Start,Stop,Increment: ') if x==z: break else: x_str_array = x_str.split(',') # splits the string where a comma pops up x = range(len(x_str_array)) # Preallocation step- makes x= the same length as x_str_array for i in range(len(x_str_array)): x[i] = int(x_str_array[i]) a=x[0] b=x[1] c=x[2] for number in range(a,b,c): print "number:", number, …

Member Avatar
Member Avatar
+0 forum 4

Hey, I have a set of types which are all arithmetic (have operators for addition, subtraction, multiplication, etc.). I want to aggregate any number of them into a single object, so I'm using the std::tuple class template and the <tuple> library (and Boost.Tuple for backward compatibility). My question is a bit of a shot in the dark: Has anyone heard or seen a tuple-like class template that implements all the arithmetic operators? For example, the std::tuple and boost::tuple classes both implement all the comparison operators which will only compile correctly if all the types contained in the tuple also have …

Member Avatar
Member Avatar
+0 forum 4

Having problems with the TypeError below: [code]order_list = ['25459 ', '12381 ', '25375 '] cursor.execute("SELECT WVGID6 , WVWHID, WVITNO, WVLOCA FROM WMRSV WHERE OHORNO IN (%s)"% tuple(order_list)) TypeError: not all arguments converted during string formatting[/code] The correct SQL should look like: [CODE]SELECT WVGID6 , WVWHID, WVITNO, WVLOCA FROM WMRSV WHERE OHORNO IN ('25459 ', '12381 ', '25375 ')[/CODE]

Member Avatar
Member Avatar
+0 forum 1

Although [url=http://en.wikipedia.org/wiki/Roman_numerals]roman numerals[/url] sneak in our lives from time to time, we(luckily) don't use them very often. Probably the reason why the Romans where not that good at calculating things. That changed, more than 1000 years later, with [url=http://en.wikipedia.org/wiki/Fibonacci]this person[/url] who introduced to the Western world the number system we all use today. But let's come to the point: this is not about a conversion but about the ways to do it. I don't even refer to the algoritm used, but C# seems to become such a rich expressive language that I'm beginning to have trouble choosing a way to …

Member Avatar
Member Avatar
+0 forum 10

Tuples are immutable objects, they cannot be changed says the Python manual. [code]my_tuple = (1, 2, 3, [4, 5, 6]) # this works my_tuple[3][2] = 7 # clearly the item at index 3 in the tuple has changed print(my_tuple) # (1, 2, 3, [4, 5, 7]) [/code]

Member Avatar
Member Avatar
+0 forum 4

I have a code designed to show the different spaces a knight can move to in a standard chess game. It needs to be a function created that outputs the possible spaces in tuples. I can't figure out how to make the output in tuples and I would appreciate it if anybody knew how to make this code more efficient. [CODE]def knightmove(x, y): and have the output turned back into letter, number form rather than the current number, number form that it is in. endloop=0 while endloop==0: xcoord=x ycoord=y xcoord=xcoord.lower() if ycoord>8: print "The 'Y' co-ordinate you entered is invalid" …

Member Avatar
Member Avatar
+0 forum 4

Starting with version 2.6 Python has introduced a new container called the named tuple. You can use it similar to a class based record structure, but it has the memory efficiency of a tuple.

Member Avatar
+1 forum 0

Here is way to put easily editable layout for input fields with standard look and collect the text variables to list for use.

Member Avatar
+0 forum 0

Here is some saved interaction in command prompt. [CODE]>>> type((1,2)) <type 'tuple'> >>> (3*x for x in (4,4)) <generator object <genexpr> at 0x00E73EB8> >>> tuple(x**2 for x in range(10)) (0, 1, 4, 9, 16, 25, 36, 49, 64, 81) >>> set(x for x in range(10)) set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> {x:x**2 for x in range(10)} SyntaxError: invalid syntax >>> x=2 >>> {x:x**2} {2: 4} >>> [{x:x**2} for x in range(10)] [{0: 0}, {1: 1}, {2: 4}, {3: 9}, {4: 16}, {5: 25}, {6: 36}, {7: 49}, {8: 64}, {9: 81}] >>> type([{x:x**2} for x …

Member Avatar
Member Avatar
-3 forum 1

I need to code a program that input will be any random string and the the output will include processes, unprocessed string. EX: Input String : XYZZXXYYXYZZXYZ Unique Prefixes : ['', 'X', 'Y', 'Z', 'ZX', 'XY', 'YX', 'YZ', 'ZXY'] Encode List : [(0, 'X'), (0, 'Y'), (0, 'Z'), (3, 'X'), (1, 'Y'), (2, 'X'), (2, 'Z'), (4, 'Y'), (3, '')] Encoded Binary String : 00101100000101100100010110101101011000001010110010100101100000100101101001000101100100011 Decoded String : XYZZXXYYXYZZXYZ If anyone can help me with this. I am very thankful and appriciated.

Member Avatar
Member Avatar
+0 forum 6

I am relatively new to python, and have run into an issue with reading a strangely formatted output file. The current format of the output file for each line is [(x,y),.....(x,y)] (tuples nested within a list?) and I need to read each line in the file and output a 3 columned file with columns X Y and Flavor where flavor is the i-th component in a defined variable. --thanks

Member Avatar
Member Avatar
+0 forum 7

I am new-ish to python and need to write a short program which will take a file with many lines of sets of coordinates alongside a defined variable of a series of letters and out a 3 columned file with columns x, y, and letter. the input file has each line in the form of [(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (-1,7), (-1, 8), (0, 8)] and there is a defined variable Prot which has the same length as the number of coordinate pairs in each line of the input …

Member Avatar
Member Avatar
+0 forum 2

The End.