Posts
 
Reputation
Joined
Last Seen
Ranked #3K
Strength to Increase Rep
+0
Strength to Decrease Rep
-0
91% Quality Score
Upvotes Received
10
Posts with Upvotes
10
Upvoting Members
7
Downvotes Received
1
Posts with Downvotes
1
Downvoting Members
1
2 Commented Posts
3 Endorsements
Ranked #486
Ranked #261
~165.27K People Reached
Favorite Tags

102 Posted Topics

Member Avatar for pyguy25

[code=Python]... for char in message: # check if the character is alphabetic if char.isalpha(): ...[/code] Regards, mawe

Member Avatar for FaZeSkwlSh00ter
0
7K
Member Avatar for sneekula

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 - …

Member Avatar for entropicII
0
45K
Member Avatar for Lardmeister
Member Avatar for bumsfeld
0
5K
Member Avatar for R.S.Chourasia

[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].

Member Avatar for TrustyTony
0
6K
Member Avatar for sneekula

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 …

Member Avatar for wallars
0
1K
Member Avatar for NetByte

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

Member Avatar for snippsat
-1
1K
Member Avatar for pyguy25

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 …

Member Avatar for j6m8
0
273
Member Avatar for cmpt

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 …

Member Avatar for ptirthgirikar
-1
160
Member Avatar for sneekula
Member Avatar for Stefano Mtangoo
0
562
Member Avatar for katharnakh

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 …

Member Avatar for snippsat
0
17K
Member Avatar for Dark_Omen

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

Member Avatar for pkc
0
425
Member Avatar for Mouche

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 :-| …

Member Avatar for vegaseat
0
1K
Member Avatar for mawe

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 ;)

1
847
Member Avatar for liz517
Member Avatar for anatashinu
0
178
Member Avatar for mattyd

I'm having trouble unzipping it on Linux. All I get is the error message [i]unsupported compression method 98[/i] :confused:

Member Avatar for vegaseat
1
243
Member Avatar for danizzil14

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" …

Member Avatar for Gribouillis
0
211
Member Avatar for Micko

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 …

Member Avatar for vegaseat
0
5K
Member Avatar for alex05

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

Member Avatar for msr_viz
0
246
Member Avatar for sneekula

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] :)

Member Avatar for sneekula
0
117
Member Avatar for Tetch

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 …

Member Avatar for Tetch
0
2K
Member Avatar for vegaseat

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 …

Member Avatar for sgssergio
0
1K
Member Avatar for Jusa

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 …

Member Avatar for pandu22
0
518
Member Avatar for fredzik

[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, …

Member Avatar for fredzik
0
304
Member Avatar for Zorbie

[code=Python]>>> import sys >>>[/code] Hmm, it seems to work. What did you expect to happen? :)

Member Avatar for StrikerX11
0
158
Member Avatar for justmonkey23

[code=Python]writer = csv.writer(open(("beta_%i.%i.%i.csv" % (now.day, now.month, now.year)), "ab")[/code]

Member Avatar for justmonkey23
0
119
Member Avatar for Matt Tacular

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

Member Avatar for ghostdog74
0
183
Member Avatar for lineman60
Member Avatar for mawe
1
556
Member Avatar for jwjazz

[code=Python]def increase(num, b2, x): if num%(b2**x) < num: return increase(num, b2, x+1) print x return x[/code]

Member Avatar for jrcagle
0
136
Member Avatar for pkraop

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; …

Member Avatar for pkraop
0
106
Member Avatar for nam5a

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]

Member Avatar for nam5a
0
115

The End.