Skip to main content

Home/ Mac Attack/ Group items tagged loops

Rss Feed Group items tagged

Benjamin Bandt-Horn

Game programming - Wikipedia, the free encyclopedia - 0 views

  • The central component of any game, from a programming standpoint, is the game loop. The game loop allows the game to run smoothly regardless of a user's input or lack thereof. Most traditional software programs respond to user input and do nothing without it. For example, a word processor formats words and text as a user types. If the user doesn't type anything, the word processor does nothing. Some functions may take a long time to complete, but all are initiated by a user telling the program to do something. Games, on the other hand, must continue to operate regardless of a user's input. The game loop allows this. A highly simplified game loop, in pseudocode, might look something like this: while( user doesn't exit ) check for user input run AI move enemies resolve collisions draw graphics play sounds end while
  •  
    The central component of any game, from a programming standpoint, is the game loop. The game loop allows the game to run smoothly regardless of a user's input or lack thereof.
Benjamin Bandt-Horn

Python : map and filter vs for loops - 0 views

  • Re: Python : map and filter vs for loops The underlying implementation of map and filter are different than loops, even though they accomplish the same thing. Which idiom runs fastest can change from version to version. Right now I think list comprehensions are the fastest. So instead of Code: filter(f, range(2,25)), the list comprehension would be Code: [x for x in range(2,25) if f(x)] and instead of Code: map(cube, range(1, 11)) the list comprehension would be Code: [cube(x) for x in range(1,11)]
  •  
    Python : map and filter vs for loops The underlying implementation of map and filter are different than loops, even though they accomplish the same thing. Which idiom runs fastest can change from version to version. Right now I think list comprehensions are the fastest.
Benjamin Bandt-Horn

gevent: A coroutine-based network library for Python - 0 views

  • gevent is a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev event loop. Features include: Fast event loop based on libev (epoll on Linux, kqueue on FreeBSD). Lightweight execution units based on greenlet. API that re-uses concepts from the Python standard library (for example there are Events and Queues). Cooperative sockets with SSL support » DNS queries performed through threadpool or c-ares. Monkey patching utility to get 3rd party modules to become cooperative »
  •  
    gevent is a coroutine-based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev event loop. Features include: Fast event loop based on libev (epoll on Linux, kqueue on FreeBSD). Lightweight execution units based on greenlet. API that re-uses concepts from the Python standard library (for example there are Events and Queues). Cooperative sockets with SSL support » DNS queries performed through threadpool or c-ares. Monkey patching utility to get 3rd party modules to become cooperative »
Benjamin Bandt-Horn

Great Python Tricks for avoiding unnecessary loops in your code - Udacity Forums - 0 views

  • To do element-wise operations on a list - for example, to produce a list consisting of each element of list A multiplied by 2 Method 1 [2*x for x in A] - this technique is called list comprehension Method 2 if you have defined a function double(x) which doubles x map(double, A) Method 3 define the function that doubles x on the fly, anonymously map(lambda x: 2*x, A)
  •  
    To do element-wise operations on a list - for example, to produce a list consisting of each element of list A multiplied by 2 Method 1 [2*x for x in A] - this technique is called list comprehension Method 2 if you have defined a function double(x) which doubles x map(double, A) Method 3 define the function that doubles x on the fly, anonymously map(lambda x: 2*x, A)
Benjamin Bandt-Horn

Classes & Iterators - Dive Into Python 3 - 0 views

  • Comprehensions are just a simple form of iterators. Generators are just a simple form of iterators
  • The first argument of every class method, including the __init__() method, is always a reference to the current instance of the class. By convention, this argument is named self.
  • self is not a reserved word in Python, merely a naming convention
  • ...6 more annotations...
  • To build an iterator from scratch, Fib needs to be a class, not a function.
  • in most cases), __iter__() simply returns self, since this class implements its own __next__() method.
  • a for loop will call this automatically, but you can also call it yourself manually
  • the __next__() method raises a StopIteration exception, this signals to the caller that the iteration is exhausted. Unlike most exceptions, this is not an error; it’s a normal condition that just means that the iterator has no more values to generate. If the caller is a for loop, it will notice this StopIteration exception and gracefully exit the loop. (In other words, it will swallow the exception.)
  • Do not use yield here; that’s a bit of syntactic sugar that only applies when you’re using generators. Here you’re creating your own iterator from scratch; use return instead
  • raise StopIteration
  •  
    Comprehensions are just a simple form of iterators. Generators are just a simple form of iterators
Benjamin Bandt-Horn

Stack data structure in python - Stack Overflow - 0 views

  • No need to jump through these loops, See 5.1.1 Using Lists as Stacks
1 - 6 of 6
Showing 20 items per page