- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 10
- Posts with Upvotes
- 10
- Upvoting Members
- 7
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
102 Posted Topics
Re: [code=Python]... for char in message: # check if the character is alphabetic if char.isalpha(): ...[/code] Regards, mawe | |
Re: Hi sneekula, sorry, I totally forgot to answer in the last thread :confused: Ok, your second question is an easy one ;) [php]import Tkinter as tk import tkMessageBox def ask_quit(): if tkMessageBox.askokcancel("Quit", "You want to quit now? *sniff*"): root.destroy() root = tk.Tk() root.protocol("WM_DELETE_WINDOW", ask_quit) root.mainloop()[/php] Ok, now the quit - … | |
Re: This should do what you want: [code=Python]print "%x" % 255[/code] | |
Re: [code=Python]a = [4,5,6] s = set(a)[/code] Now s is a set :) For further info have a look at the [url=http://docs.python.org/lib/types-set.html]documentation[/url]. | |
Re: sneekula, I don't want to sound rude, but your one-sentence-question-posts are annoying. Why don't you try to find the answer alone first? If you're stuck, post what you have tried and we will try to help you. BTW: The internet is full of isprime functions in any language you can … | |
Re: Hi! You have to install idle first (via apt-get or synaptic) ;) The dependency package is called [i]idle[/i], the current one [i]idle-python2.4[/i]. Regards, mawe | |
Re: Hi! Well, you did it ... nearly :) [code]words = string.split(p)[/code] Ok, [i]words[/i] is now a list, and it's elements are the words in the sentence. You want to know how many words there are in the sentence ... so ... how do you get the number of elements in … | |
Re: Hi! The first one without any if-elif: [code=Python]def search(l, key): return key in l[/code] For the second one, [b].index()[/b] is your friend ;) [code=Python]def search(l, key): if key in l: return l.index(key) return False[/code] EDIT: Oh sorry, I didn't see it had to be recursive. [code=Python]def search(l, key, index=0): if … | |
Re: Hi! [code]for i in data: print "#" * i[/code] :) Regards, mawe | |
Re: Hi! [quote="Python Doku"]__call__( self[, args...]) Called when the instance is ``called'' as a function; if this method is defined, x(arg1, arg2, ...) is a shorthand for x.__call__(arg1, arg2, ...). [/quote] So ... [code]In [35]: class A: ....: def __init__(self): ....: print "init" ....: def __call__(self): ....: print "call" ....: In … | |
Re: Hi! [quote="Dark_Omen"] I know this is from awhile back, but you can use print in ruby and it does the same thing as puts. [/quote] Nor really ;). Try this [code]print "not" puts "the" p "same"[/code] Regards, mawe | |
![]() | Re: Hi! Nice! :) I didn't have a detailed look on the code, but *) instead of [code]% (board_list[0], board_list[1], board_list[2], board_list[3], board_list[4], board_list[5], board_list[6], board_list[7], board_list[8]) [/code] it may be easier to write [inlinecode]% (tuple(board_list))[/inlinecode] ;) *) I won several times, but the program didn't notice it. That's frustrating :-| … |
The name says it all, I think. You have a nested list, you want to flatten it (e.g. because you want to count the occurence of an element), this function is all you need ;) | |
Re: liz517, could you please explain what your code [i]should[/i] do. | |
Re: I'm having trouble unzipping it on Linux. All I get is the error message [i]unsupported compression method 98[/i] :confused: | |
Re: Another way: [code=Python]def group( lst, n ): ''' splits an iterable in parts with length n, e.g. group( [1,2,3,4], 2 ) ==> [ (1,2), (3,4) ] ''' return zip( *[ lst[i::n] for i in range(n) ] ) aa_dict = { "AAA": "A", "GGG": "C", "CCC": "B" } s = "AAAGGGCCC" … | |
Re: Hi! Here's a snippet using Tkinter: [code]from Tkinter import * def click(key): if key == "=": # here comes the calculation part pass # but that's up to you ;-) else: display.insert(END, key) root = Tk() keys = ["789/", "456*", "123-", "0.=+"] display = Entry(bg="white") display.grid(row=0,column=0,columnspan=4) x,y = 1,0 for … | |
Re: Hi! I guess what you are looking for is [b]basename[/b] and [b]dirname[/b]. [code] $ dirname /users4/st/jdoe/prog.c /users4/st/jdoe $ basename /users4/st/jdoe/prog.c prog.c [/code] Regards, mawe | |
Re: I once wrote one :icon_wink: It's part of one of the greatest periodic table programs of the world *cough*. You can find it [url=http://freshmeat.net/projects/pyperiod/]here[/url]. Then there is [url=http://pyparsing.wikispaces.com/]pyparsing[/url]. You might be interested in one of the examples ... [url=http://pyparsing.wikispaces.com/space/showimage/chemicalFormulas.py]chemicalFormulas.py[/url] :) | |
Re: 700 loc for a simple roulette game? I guess you could shorten it a bit :icon_wink: [code=Python]if spin == 3 or spin == 4 or spin == 5 or spin == 6 or spin == 7 or spin == 8 \ or spin == 9 or spin == 10 or … | |
Re: I think OCaml is still missing: [code]print_endline "Hello World!";;[/code] Two GUI versions: The first one with the built in Graphics module: [code]Graphics.open_graph " 80x20";; Graphics.moveto 5 5;; Graphics.draw_string "Hello World";; read_line () [/code] And one with Tk: [code]open Tk let top = openTk () let l = Label.create top ~text:"Hello … | |
Re: Hi, your "error" is a very common source of confusion :) Let's take a slightly simpler example: [code=Python]In [1]: lst = ["a", "b", "b", "d"] In [2]: for elem in lst: ....: print "before: ", lst # check the list ....: print elem, lst.index(elem) # check which element we are … | |
Re: [quote]But I'm again puzzled by how Tkinter does things. Some examples of code at the beginning say "from Tkinter import *" and some say "import Tkinter as tk" and I've even seen "from Tkinter"...nothing else?[/quote] Let's see how you e.g. call an Entry with these (from Tkinter alone won't work, … | |
Re: [code=Python]>>> import sys >>>[/code] Hmm, it seems to work. What did you expect to happen? :) | |
Re: [code=Python]writer = csv.writer(open(("beta_%i.%i.%i.csv" % (now.day, now.month, now.year)), "ab")[/code] | |
Re: Hi! [code=Python]print "\\".join((str1, str2))[/code] or [code=Python]print "%s\\%s" % (str1, str2)[/code] If you want to make this os-independent, have a look at the [b]os[/b] module ([i]os.path.join[/i] might be your friend :)) Regards, mawe | |
Re: [i]str()[/i] is your friend. [code=Python]FILE.writelines( str(b) )[/code] | |
Re: [code=Python]def increase(num, b2, x): if num%(b2**x) < num: return increase(num, b2, x+1) print x return x[/code] | |
Re: Hi, here's one way (not very clever, but it works): [code=Perl]@numbers = (12, 12, 23, 123, 3, 234, 22333, 223, 3); foreach $number (@numbers) { # fill all numbers with whitespace to a length of 5 $number = sprintf("%-5i", $number); # replace the whitespaces with . $number =~ s/ /./g; … | |
Re: You don't need a [i]begin[/i] in Python,: [code=Scheme](if (condition) (begin (do-something-1) (do-something-2)) do-something-else)[/code] [code=Python]if condition: do_something_1 do_something_2 else: do_something_else[/code] |
The End.