These are applicable to programming in general (Python -> import this)

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

On second thought it is more reasonable to shuffle the order of keys like woooee says.

saharsweeto commented: plz help me +0

Just do the black triangles on white background or vice versa.

You are calling the function instead of passing as command parameter.

You do not do that. You have design fault.

This code seems to be explained with diagram of the state machine at
http://www.python-course.eu/finite_state_machine.php

you have many undefined and unused/unnecessary variables. Especially clumsy are first lines. Also the variable names are cryptic.

Twin802 commented: This doesn't help me at all... +0
jbennet commented: not javame -3

We equal your effort, teacher actually even almost gave the pseudocode.
[CODE]
calculate_triangle()
while want_continue():
calculate_triangle()
[/CODE]

(-2)*(-2)+ 4 = 4 + 4 = 8 Didn't learn multiplication yet? ;)

[CODE]>>> def are_same(a, b):
return set(a) == set(b) and len(a) == len(b)

are_same(("foo", "bar", "baz"), ("baz", "foo", "bar", "baz"))
False
are_same(("foo", "baz", "bar", "baz"), ("baz", "foo", "bar", "baz"))
True
[/CODE]

For hashability use frozenset or tuple of sorted values. BTW other formulation from this is:
[CODE]>>> def are_same(a,b):
return sorted(a) == sorted(b)

are_same(("foo", "bar", "baz"), ("baz", "foo", "bar", "baz"))
False
are_same(("foo", "baz", "bar", "baz"), ("baz", "foo", "bar", "baz"))
True
[/CODE]

lrh9 commented: This is wrong. Equality of length isn't equality of the amount of elements. -1

numpy histogram function looks close to your needs, it is designed for using with Python language though, probably written with C though and source code is open source.

[url]http://amusecode.org/doc/examples/simple/salpeter.html[/url]

Maybe worth to hunt through C++ libraries for histogramming?

WaltP commented: We know you LOVE Python -- but all answers in C/C++ do not have to be Python oriented. -4

The package directory is not on path or pythonpath. What is your need for Python? Did you consider [URL="

[QUOTE=tonyjv;1586964]Sorry giving Python code but I mean in Python this (value to binary string, valid range 0..255)
[CODE]>>> valtobin = ["{0:08b}".format(val)
for val in range(256)]

int(valtobin[111],2)
111
for test in range(256):
assert int(valtobin[test], 2) == test

[/CODE]
[/QUOTE]

Posted snippet to Python forum: [URL="

After graduating to GUI, it looks worthwhile to check patterns from [url]http://ui-patterns.com/[/url]

WaltP commented: What does that website have to do with numeric input? -3

Use datetime from datetime for time arithmetic and formating and shelve, json or cPickle for savĂ­ng Python data.

You can use normal print formating operations with % operator or .format method to write to file formated text without csv module. To keep space in data easiest is to use ';' as separator which rarely occurs in data or quoting of information.

I would do two variable assignment instead of temp variables needed in other languages. Looks nice code inspite of this point. Irritates me though that there seems not be faster way to split list for quicksort than doing two passes of list with complement conditions.

[CODE]KEYWORDS = ['Blues', 'Bossa']
counterline = []
counter = 0
for line in song:
for word in line.split()
counter+=1
if word in KEYWORDS:
counterline.append(counter)
x=random.sample(line,10)
print x,
[/CODE]I'm expecting once it found the selection, from that selection it will randomly select 10 of the lines that had the KEYWORDS in them and report them out.

See my code snippet of poker hands I posted.

[CODE]import numpy as np

def f(x): return np.array([1,1,1,1,1], dtype=np.float32) * x

g = np.vectorize(f, otypes=[np.ndarray])
a = np.arange(4)

print(a)
print repr(g(a))
[/CODE]

You must not use bin as variable.

Move module to same directory as main script or configuration file to same directory as modules or say subdirectory config.

Put your code better place than Desktop and put that to path.

lrh9 commented: Not the correct answer. +0

Of course it could be considered user responsibility, but I do not personally like that the calculator does not allow to continue from result and saves formula to memory instead of evaluating the result automatically.

For example:
10/3 M-> = result: 3.333333

  • M<- =
    result: *10/3.0first char not in -+0123456789.--> Error!

1/3=3
result:
3first char not in -+0123456789.--> Error!

If you learn simple list comprehensions you can do simpler way (python 2.6)

[CODE]for limit in (-1,1,3):
print [y in x if y>limit][/CODE]

Sorry, I am lazy to reed your code so wrote this myself for your example strings:
[CODE]start = '11:20AM'
finish = '9:15PM'

def hours(tim):
if tim.endswith('AM'):
st = tim.rstrip('AM').split(':')
pm = 0
elif tim.endswith('PM'):
st = tim.rstrip('PM').split(':')
pm = 12
else: raise ValueError, 'Missing AM or PM'

return (pm+int(st[0])+int(st[1])/60.0)

print 'Start',start,', finish',finish
print "Decimal hours: start %.1f, finish %.1f" % (hours(start),hours(finish))
print "%.1f hours" % (hours(finish)-hours(start))

[/CODE]

solved?

Also, see the code snippet on checking numeric input at:
[url]http://www.daniweb.com/code/snippet284490.html[/url]

Paul Thompson commented: This is a code snippet, it is in the wrong place -1

[QUOTE=kur3k;1221079]For example[CODE]# -- coding: utf-8 --

def check(number):
if number % 2 == 0:
return True
else:
return False

while True:
try:
number = int(raw_input("> Number "))
except ValueError:
print "> ERROR!"

  if check(number) == True:
     break
  else:
       continue[/CODE][/QUOTE] 

[CODE]# -- coding: utf-8 --
from future import print_function

def isodd(number): return number % 2

number=''
print("Give 'quit' to finish program.")
while number.lower() != 'quit':
if number: print('Wrong input, try again')
try:
number = raw_input("Integer to check = ")
if isodd(int(number)):
print('You gave odd number!')
else:
print('You gave even number!')
number=''
except ValueError:
continue

print('Bye, bye')
[/CODE]

Here is some ways, first is to overcome too long lines, second to save typing.

The second is not so useful maybe as you think, because Python is using byte code internally and then for speed for example the length of text does not matter so much. I only give it to show how functions are equal position with other values in Python.

[CODE]for link in ['javascript:asdfajfd.js','mailto:fasf@dsaf.saf', 'sdfaf.doc','flasdjf.html','afjdalfj.ppt','fasdfa.xls']:
if not link.startswith("javascript") and not link.startswith("mailto") and not link.endswith("pdf") and not link.endswith("ppt"):

do something
    print 'Here we are',link
splitting condition to multiple lines with using of extra parenthesis
if (
    not(
         link.startswith("javascript") or link.startswith("mailto")
         )
    and not (
        link.endswith("pdf") or link.endswith("ppt")
        )
    ):
    #do something
    print 'Here we are again',link
ls = link.startswith
le = link.endswith
if not ls("javascript") and not ls("mailto") and not le("pdf") and not le("ppt"):
     #do something
    print 'And even here',link

[/CODE]

Neat coding vegaseat: [CODE] first, last, score1, score2, score3 = line.split(',')[/CODE]