#### Category : tuples

l=[(A,B),(A,C),(E,F)] Where A is equal to B and A is equal to C and E is equal to F. I need to group the elements equal to each other in the same tuple. result=[(A,B,C),(E,F)] How can i do that? Source: Python..

Read more

u_list = input("put numbers: right now: ") List = u_list.split(",") t = tuple(List) print("Tuple: ",t) print("list: ",List) why do you need a comma in front of the variable: t variable: List? I mean the one where there is ,t – comma in front of the t . Source: Python-3x..

Read more

I’ve managed to adjust color when cursor hovers over a tkinter canvas rounded rectangle button using this: def shade_rgb(rgb): """ Adjust shade of rgb by 25% (value 64 out of 256) :param rgb: tuple of red, green, blue integers 0 to 255 :returns: tuple of red, green, blue integers 0 to 255 """ converted = ..

Read more

(‘word1’, ‘word2’) If I have a tuple, how can I add all of the words in the tuple into one string? Desired output: word1 word2 Source: Python..

Read more

There is list of list of tuples: [[(0, 0.5), (1, 0.6)], [(4, 0.01), (5, 0.005), (6, 0.002)], [(1,0.7)]] I need to get matrix X x Y: x = num of sublists y = max among second eleme throught all pairs elem[x,y] = second elem for x sublist if first elem==Y 0 1 2 3 4 ..

Read more

input file: 1 2 3 4 5 what I have at this time: filename=input("Please enter the filename or path: ") with open(filename, ‘r’) as file: filecontents=tuple(map(int, file.read().split())) print(filecontents) output: (1,2,3,4,5) intended output: 1 2 3 4 5 Source: Python..

Read more

I have the following variable: data = [([‘a’, ‘b’, ‘3’], [‘c’, ‘a’, ‘r’]), ([‘*’, ‘[‘, ‘e’], [’33’, ‘gh’, ‘ew’]), ([’23^’, ‘re#’, ‘4\$’], [‘tr’, ‘fF’, ‘5%’])] I want to write data into a CSV file as follows: a c b a 3 r * 33 [ gh e ew 23^ tr re# fF 4\$ 5% Note ..

Read more

I have a list of tuples called job_details in this format [(job, company, salary)] I have sorted them with the highest salary like this: job_details.sort(key=lambda a: a, reverse=True) Next, I want to have only the first result so that I can give a link "Show more" In my view how do I display that detail? ..

Read more

I want to sort a list of tuple for a user defined condition within the list. Below is my list of tuples. new_list = [(‘eth2’, ‘2001:0db8:::8a2e:0370:7334’), (‘new-MGMT’, ‘10.10.0.1’), (‘management’, ‘20.20.0.2’), (‘eth2.1’, ‘20.20.3.1’), (‘eth2.2’, ‘30.30.3.1’)] My condition to sort is: The interface name which contains MGMT or management needs to be moved to the begining of ..

Read more

I have a nested list in python and want to extract some numbers of it. Each sublist contains tuples and each tuple has two numbers which first one is always 2. I want to extract second number of tuples from sublists that second number of all their tuples exist in another list (check_values). this is ..

Read more