performance « List « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » List » performance 

1. Python: List vs Dict for look up table    stackoverflow.com

I have about 10million values that I need to put in some type of look up table, so I was wondering which would be more efficient a list or dict? I know ...

2. Cost of list functions in Python    stackoverflow.com

Based on this older thread, it looks like the cost of list functions in Python is:

  • Random access: O(1)
  • Insertion/deletion to front: O(n)
  • Insertion/deletion to back: O(1)
Can anyone confirm whether this is ...

3. Fastest nested loops over a single list (with elements remove or not)    stackoverflow.com

I am looking for advice about how to parse a single list, using two nested loops, in the fastest way, avoiding doing len(list)^2 comparisons, and avoiding duplicate files in groups. More precisely: ...

4. Getting a list of child entities in App Engine using get_by_key_name (Python)    stackoverflow.com

My adventures with entity groups continue after a slightly embarrassing beginning (see Under some circumstances an App Engine get_by_key_name call using an existing key_name returns None). I now see that I ...

5. Python: How much space does each element of a list take?    stackoverflow.com

I need a very large list, and am trying to figure out how big I can make it so that it still fits in 1-2GB of RAM. I am using the ...

6. efficiently knowing if intersection of two list is empty or not, in python    stackoverflow.com

Suppose I have two lists, L and M. Now I want to know if they share an element. Which would be the fastest way of asking (in python) if they share an ...

7. how to efficiently get the k bigger elements of a list in python    stackoverflow.com

What´s the most efficient, elegant and pythonic way of solving this problem? Given a list (or set or whatever) of n elements, we want to get the k biggest ones. ( You ...

8. Python: speed up removal of every n-th element from list    stackoverflow.com

I'm trying to solve this programming riddle and although the solution (see code below) works correctly, it is too slow for succesful submission.

  • Any pointers as how to make this ...

9. Is there a way to circumvent Python list.append() becoming progressively slower in a loop as the list grows?    stackoverflow.com

I have a big file I'm reading from, and convert every few lines to an instance of an Object. Since I'm looping through the file, I stash the instance to a list ...

10. Python performance: iteration and operations on nested lists    stackoverflow.com

Problem Hey folks. I'm looking for some advice on python performance. Some background on my problem: Given:

  1. A (x,y) mesh of nodes each with a value (0...255) starting at ...

11. Fastest way to uniqify a list in Python    stackoverflow.com

Fastest way to uniqify a list in Python without preserving order? I saw many complicated solutions on Internet - could they be faster then simply:

list(set([a,b,c,a]))
?

12. Most efficient way for a lookup/search in a huge list (python)    stackoverflow.com

Hey guys, -- I just parsed a big file and I created a list containing 42.000 strings/words. I want to query [against this list] to check if a given word/string belongs ...

13. itertools.islice compared to list slice    stackoverflow.com

I've been trying to apply an algorithm to reduce a python list into a smaller one based on a certain criteria. Due to the large volume of the original list, in ...

14. Python Sets vs Lists    stackoverflow.com

In Python, which data structure is more efficient/speedy? Assuming that order is not important to me and I would be checking for duplicates anyway, is a Python set slower than a ...

15. Best data-structure to use for two ended sorted list    stackoverflow.com

I need a collection data-structure that can do the following:

  • Be sorted
  • Allow me to quickly pop values off the front and back of the list O(log n)
  • Remain sorted after I insert a ...

16. Fastest method in merging of the two: dicts vs lists    stackoverflow.com

I'm doing some indexing and memory is sufficient but CPU isn't. So I have one huge dictionary and then a smaller dictionary I'm merging into the bigger one:

big_dict = {"the" : ...

17. Optimizing operations on lists    stackoverflow.com

I need to process lots of data in lists and so have been looking at what the best way of doing this is using Python. The main ways I've come up ...

18. Python list, lookup object name, efficiency advice    stackoverflow.com

Suppose I have the following object:

class Foo(object):
  def __init__(self, name=None):
    self.name = name

  def __repr__(self):
    return self.name
And a list containing multiple instances, such ...

19. Comparing Value of one list inside Gigantic Two Dimen list in python, Fastest way?    stackoverflow.com

I want to compare if value of one list exist in value of other list.They are huge (50k + items, from database).

EDIT:

I also want to mark the record which is ...

20. Python loop to [:-1]    stackoverflow.com

So, I notice that calling array[:-1] is going to clone the array. Say I have a large array with like 3000 elements in it. I don't want it to be cloned ...

21. how to optimally count elements in a python list    stackoverflow.com

This is almost the same question than here, except that I am asking about the most efficient solution for a sorted result. I have a list (about 10 integers randomly between ...

22. Fastest way to swap elements in Python list    stackoverflow.com

Is there any any faster way to swap two list elements in Python than

L[a], L[b] = L[b], L[a]
or would I have to resort to Cython or Weave ...

23. Comparing 40 million lines in a file with 6 million list items in Python    stackoverflow.com

I have a file with 40 million entries in the form of:

#No Username
And I have a list with 6 million items, where each item is a username. I want to find the ...

24. List of big-O analysis for Python datastructures    stackoverflow.com

Is there a list of the different data structures and their big-O access times for Python? I was rummaging through the standard library docs and didn't see any, hence the question. :-) ...

25. Python - How to check list monotonicity    stackoverflow.com

What would be an efficient and pythonic way to check list monotonicity?
i.e. that it has monotonically increasing or decreasing values? Examples:

[0,1,2,3,3,4] # This is a monotonically increasing list
[4.3,4.2,-2]  # This ...

26. Which performance have cPython sets in comparison to lists?    stackoverflow.com

I have just found these performance notes for cPython lists: Time needed for python lists to ....

  • ... get or set an individual item: O(1)
  • ... append an item to the list: ...

27. What's the fastest way to compare two large lists of 1's & 0's and return the difference count/percentage?    stackoverflow.com

I'm in need of a method to quickly return the number of differences between two large lists. The contents of each list item is either 1 or 0 (single integers), and ...

28. Python, use the lists in the list, or objects in the list?    stackoverflow.com

I have a list and in each list element, I need some details. What will be more efficient to use the list in the list [['brown', 'wood', 2], ['red', 'box', 3 ...

29. Discontinuous slice in python list    stackoverflow.com

I'm looking for an efficient way of achieving this, which I think is a slicing-like operation:

>>> mylist = range(100)
>>>magicslicer(mylist, 10, 20)
[0,1,2,3,4,5,6,7,8,9,30,31,32,33,34,35,36,37,38,39,60,61,62,63......,97,98,99]
the idea is: the slicing gets 10 elements, then skips 20 ...

30. Python function slows down with presence of large list    stackoverflow.com

I was testing the speeds of a few different ways to do complex iterations over some of my data, and I found something weird. It seems that having a large list ...

31. Repeatedly appending to a large list (Python 2.6.6)    stackoverflow.com

I have a project where I am reading in ASCII values from a microcontroller through a serial port (looks like this : AA FF BA 11 43 CF etc) The input is ...

32. what's a simple way to search a very long text file for a word in python?    stackoverflow.com

I want to create a very simple spell checker using a text file with an alphabetized list of about 80000 common words. What's a simple but efficient way to search the ...

33. running time of list.index(x) in python    stackoverflow.com

I'm referring to this: http://docs.python.org/tutorial/datastructures.html what would be the running time of list.index(x) function in terms of big O notation?

34. Python and performance of list comprehensions    stackoverflow.com

Suppose you have got a list comprehension in python, like

Values = [ f(x) for x in range( 0, 1000 ) ]
with f being just a function without side effects. So all ...

35. Python splitting big lists into smaller lists for check performance?    stackoverflow.com

What is the best way to split a large list (over 1000 items) for performance purposes? And use "parts" of a large list? For example; I have a list of 10k addresses ...

36. How does Python handle checking 'if object in list'    stackoverflow.com

I'm wondering because I need to have have a function that is disgustingly fast at checking if a word is in a dictionary list - I'm considering leaving the dictionary as ...

37. Faster way to get a directory listing than invoking "ls" in a subprocess    stackoverflow.com

After a search, and some test runs both os.popen()+read() and subprocess.check_output() seem to be almost equivalent for reading out the contents of a folder. Is there a way to improve either ...

38. Splitting list into multiple lists to gain a speedup?    stackoverflow.com

Let's say my list is about 1,000,000 entries long. To acess an item, the time would be O(500,000), which seems very long to me. What happens when I split the ...

39. Python 2 lists compare optimization    stackoverflow.com

Given: Two csv files (1.8 MB each): AllData_1, AllData_2. Each with ~8,000 lines. Each line consists of 8 columns. [txt_0,txt_1,txt_2,txt_3,txt_4,txt_5,txt_6,txt_7,txt_8] Goal: Based on a match of txt_0 (or, AllData_1[0] == AllData_2 ), ...

40. Unwrapping a list from the inside    stackoverflow.com

I am updating a legacy Python script, and was wondering if it is possible to unwrap a list from inside another list, or more generally to unwrap a list into just ...

41. Which is the fastest way to search a value within a set of many "range" objects in Python    stackoverflow.com

I have a list of many Python objects like this:

class RangeClass(object):

    def __init__(self,address,size):
        self.address=address
        ...

42. Python - Identify Common Values    stackoverflow.com

I am currently using Python 2.7. I currently have three columns in an Excel document all with different integer values in. The amount of values can vary ranging from 10 through ...

43. Checking information in a dataset in Python    stackoverflow.com

I currently have a requirement to make a comparison of strings containing MAC addresses (eg. "11:22:33:AA:BB:CC" using Python 2.7. At present, I have a preconfigured set containing the MAC address ...

44. How to remove all duplicates from list except one element in Python?    stackoverflow.com

I already know how to remove all duplicates from List by using set:

ls = list(set(ls))
What i want to know is there any way to remove all duplicates except one element instances, ...

45. Time complexity of creating nested lists in Python    stackoverflow.com

I have run into an oddity with creating nested lists in Python 2.6.6. Consider the following two functions:

def lists(n):
    start_time = time.time()
    lists = [None]*n
  ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.