Re: tuples and lists Programming Software Development by Zonr_0 Tuples are great for constants because you won't accidently change them, they're also faster and use less space then lists, iirc. Tuples Programming Software Development by dustbunny000 I am having problems with tuples. I have a list of tuples that have (x,y,z) coordinates. Each coordinate is a float. How can I calculate the distance between two coordinates? Can you do this with tuples? [CODE]coord=[] for line in CN_list: x=line[30:39] y=line[38:47] z=line[46:55] coord.append((float(x),float(y), float(z)))[/CODE] Tuples Programming Software Development by hunterm I thought I understood how tuples work, but that is not the case. [code=python] lose = ['skldhf', 'laweoirht', 'skdljhflkjhs'] print lose [/code] How would I get it to print of the three phrases randomly? No, those aren't what I will be actually using, I just haven't come up with what I want to use yet. Thanks for the help. Tuples example Programming Software Development by vlady … [COLOR="Green"]It is common to use tuples as keys in dictionaries (primarily because you can’t use… This loop traverses the keys in directory, which are tuples. It assigns the elements of each tuple to last and… corresponding telephone number. There are two ways to represent tuples in a state diagram. The more detailed version shows … tuples and lists Programming Software Development by Mouche So if I want to store a list of items (such as a bunch of instances of a class), what's better to use: tuples or lists? I understand that lists are mutable, so what are the advantages to tuples? Re: tuples exercise, most frequent letters Programming Software Development by vegaseat …about using a list of (char_frequency, char) tuples is that they also sort the characters that … ... [code]# create a list of (char_frequency, char) tuples import pprint text = "supercalifragilisticexpialidocious" # create a…list(text) # create a list of (letter_freq, letter) tuples # set(ch_list) creates a set of unique characters # … tuples exercise, most frequent letters Programming Software Development by vlady …, I don´t know how to remove duplicate in "tuples". Please can you help me? [(2, 'o'), (2, 'n… Re: tuples exercise, most frequent letters Programming Software Development by TrustyTony I would include the letter in the tuple appended to list at line 8 or do loop over count, letter tuples of frequency and letter prepared by the zip function. I would not definately use l as variable name, use full, understandable words. Re: Tuples Programming Software Development by griswolf Sure you can. The code looks something like this (done in a hurry):[CODE]import math s = (1,2,3) t = (5,5,5) x0 = (s[0]-t[0])**2 x1 = (s[1]-t[1])**2 x2 = (s[2]-t[2])**2 print math.sqrt(x0+x1+x2)[/CODE] Hope this helps Re: Tuples Programming Software Development by _Nestor First of all lose is not a tuple its a list a tuple is declared as follows [code=python] lose = ('fdasf','dfasf','asdf') [/code] for pseudo random numbers you import the random module [code=python] i = range(len(lose)) random.shuffle(i) [/code] The values of i are now shuffled and can be used to access the tuple in "random" … Re: Tuples Programming Software Development by hunterm Thanks. Is it possible to make a tuple out of functions instead of 'slkdhfk'? Thanks. Re: Tuples Programming Software Development by jlm699 What, you mean like this? [code=python] >>> def funA(): ... print 'A' ... >>> def funB(): ... print 'B' ... >>> def funC(): ... print 'C' ... >>> my_tup = ( funA, funB, funC ) >>> for each_function in my_tup: ... each_function() ... A B C >>> [/code] Re: Tuples Programming Software Development by _Nestor To explain the previous code a bit clearer [code=python] i = range(len(lose)) [/code] This returns a list to i so if lose is [code=python] lose = ('efesef','esfes','asefe') [/code] then i is [code=python] i = [0,1,2] [/code] the code random.shuffle(i) is just shuffling the number so you can index different items in the list for example after random… Re: Tuples Programming Software Development by sneekula Tuple elements can be accessed by their index: [code=python]my_tup = ('fdasf','dfasf','asdf') print my_tup[0] # --> fdasf print my_tup[2] # --> asdf [/code] Re: Tuples Programming Software Development by hunterm Thanks for all the help! Sort a List of Tuples by Index Programming Software Development by Ene Uran A list of tuples is easy to sort for items in the tuples. This snippet shows you how to sort a (character, frequency) tuple either by character or by frequency. One useful example would be the sorting and display of a list of (player, score) tuples, you might find in a game. numbering of multi tuples at once....... Programming Databases by harikrishna439 I have 10 tuples in my table.And now I create another field of serial number.For all tuples, the field of serial number contain null values. So, is there any way to numbering all the tuples from 1 to 10 at once. Any answer could be appreciated...... Deleting Same Tuples Programming Databases by karan_21584 … is this. I have a table which consist of some tuples. i didnt set any primary key. by mistakely i entered… the same values for two tuples. i want to delete a single tuple without copying the… Selecting all tuples with maximum value for an attribute Programming Databases by kartik14 … order of this attribute. My query should retrieve all the tuples which have the maximum value for this derived attribute. If… of the required results. How can I get all the tuples with the maximum value ?? Thanks in advance.. EDIT*: The only… Combinging parts of tuples together Programming Software Development by iuessele … from a deck of playing cards? i set up two tuples, one with the ranks and the other with the suits… Ace of spades - King of spades......combining parts of my tuples together. [rank = (("A", "2", "3… How can I create a list of randomly generated tuples? Programming Software Development by MONODA … am looking for a way to generate a list of tuples with random values; something like the range function except I… want to have a list of tuples rather than integers. I would also like it to generate… Retrieving nested tuples using recursion Programming Software Development by jjma …. I'm trying to make a function that takes nested tuples and returns a list of each nested tuple. I managed… to make a function that returns the values of the tuples (which are strings), but cannot figure out how to retrieve… Re: numbering of multi tuples at once....... Programming Databases by harikrishna439 …, of course.But If I have more number of distinct tuples, it is somewhat difficult to identify each and every field… Removing tuples from a list of them? Programming Software Development by james.lu.75491856 …(x): x not in list I think it's because tuples are immutable, so their diffrent objects with the same value…. You see, `(4,0)` is in `notdone`.Why tuples?Because you can't hash a list. I'm using… Re: Deleting Same Tuples Programming Databases by ~s.o.s~ …. Take a look at it once again. I delete those tuples who don't satisfy the criteria of having the max… Re: List vs Tuples Programming Software Development by Zetlin … name you would do this" del cats[0] [/code] Tuples are just like lists, but you can't change their…',' December') "So that’s the difference between lists and tuples. A list can be modified but a tuple cannot be… Re: How can I create a list of randomly generated tuples? Programming Software Development by Ene Uran Maybe something like this: [code=python]import random low = 1 high = 9 mylist = [(random.randint(low, high), ) for k in range(10)] print(mylist) """ a possible display of one element tuples --> [(9,), (5,), (6,), (2,), (8,), (3,), (4,), (2,), (6,), (1,)] """ [/code] Re: Retrieving nested tuples using recursion Programming Software Development by jjma … idea is to make a list of each of the tuples in the nested tuple - e.g.: [CODE](('A','B'),'C… Re: Removing tuples from a list of them? Programming Software Development by james.lu.75491856 uh, now the flashcards are tuples! for i in showns: s = partial(random.choice, notdone) print notdone a = s() print a notdone.remove(a) b = s() flashcards[a] = Flashcard((x*20,y*100),i) flashcards[b] = Flashcard((x*20,y*100),i) Python tuples and Sql query Programming Software Development by sliver_752 …. The query becomes even more complex when i have nested tuples. Any Ideas?