Skip to content
Advertisement

Tag: tuples

Python sorted not sorting Counter output properly

I am trying to sort out min page load time and max page load time from Apache access log file. After parsing the log file and sorting using sorted I am seeing weird sorting. The above code sorting thousandths and only then sorting hundreds: As you see 455 and 677 are at the end, but if you look separately at

Changing the value of tuple inside a nested list

How do I change the second value of the first tuple in the first list by force?? Please help! Thanks in advance. Answer Tuples are immutable. You would need to replace it instead. Since lists are mutable, you would replace the first element of the first list with a new tuple having a changed second value. This would give you:

Getting a specific element from a list of tuples

In using Spacy, I have the following: It is a list of tuples. I want to extract the person element. This is what I do: What would be a better way? Answer To keep all first element if second element is PERSON from first list use a list comprehension notation with a if at the end This corresponds to

Output tuple from a list without ‘for’

I need to output tuple from a list without for. Tell me please, how I can do it? I have list of all permutation for some n: and I need (for example, if n = 2) : I tried, to use sum(l, []), but I have not idea, how I can do line break. Answer What you get back from

python: class vs tuple huge memory overhead (?)

I’m storing a lot of complex data in tuples/lists, but would prefer to use small wrapper classes to make the data structures easier to understand, e.g. would be preferable over however there seems to be a horrible memory overhead: and Why? is there any obvious alternative solution that I didn’t think of? Thanks! (I know, in this example the ‘wrapper’

How to create a tuple of an empty tuple in Python?

How can I create a tuple consisting of just an empty tuple, i.e. (())? I have tried tuple(tuple()), tuple(tuple(tuple())), tuple([]) and tuple(tuple([])) which all gave me (). The reason that I use such a thing is as follows: Assume you have n bags with m items. To represent a list of items in a bag, I use a tuple of

Nested List of Lists to Single List of tuples

I’m trying to turn a nested list of lists (number of lists can be 2 lists +) into a single list of tuples. The list looks something like this: And I would like for it to be like this: I know that if you do zip(list1, list2), it becomes a list of tuple. But how do I go about doing

pop/remove items out of a python tuple

I am not sure if I can make myself clear but will try. I have a tuple in python which I go through as follows (see code below). While going through it, I maintain a counter (let’s call it ‘n’) and ‘pop’ items that meet a certain condition. Now of course once I pop the first item, the numbering all

matplotlib 2d line line,=plot comma meaning

I’m walking through basic tutorials for matplotlib, and the example code that I’m working on is: Does anyone know what the comma after line (line,=plt.plot(x,y,’-‘)) means? I thought it was a typo but obviously the whole code doesn’t work if I omit the comma. Answer plt.plot returns a list of the Line2D objects plotted, even if you plot only one

Advertisement