4,305 Posted Topics

Member Avatar for vegaseat

I have joined the thousands who have done it before, and have compared a number of sorting routines. The sorting is done on the same random-integer arrays. No surprises, quicksort wins this simple comparison hands down. There are clever combinations of sorting routines that are faster, like the snippet by …

Member Avatar for vegaseat
2
253
Member Avatar for Fon_1

My rusty brain thinks that graphics.h comes from the ancient Turbo C days. There are ways to still include it in newer compilers, see: http://www.codewithc.com/how-to-include-graphics-h-in-codeblocks/

Member Avatar for vegaseat
0
135
Member Avatar for Dimitris_1

Sharp eye! Too bad that the compiler does not catch an obvious mistake like this. :) if(fp==NULL) ; // do nothing is correct code

Member Avatar for vegaseat
0
164
Member Avatar for vegaseat

I am sitting in front of a brandnew 27 inch Apple Macintosh running on OS X Yosemite, trying to compile a timed insertion sort from my Windows days. The Xcode app is a sweatheart, but there are some Windows things in the code that cause a problem. This line ... …

Member Avatar for vegaseat
0
274
Member Avatar for vegaseat

Just a couple of number tricks to check Go's mathematical abilities. If you have more, let's show them here.

Member Avatar for vegaseat
2
438
Member Avatar for lewashby

If you need your results sorted by frequency and then words, see ... https://www.daniweb.com/software-development/python/threads/20774/starting-python/21#post2169592

Member Avatar for vegaseat
0
2K
Member Avatar for vegaseat

A few hundred years ago the glorious leader of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then doubling it for every …

Member Avatar for vegaseat
2
8K
Member Avatar for Tcll

Module enum is new in Python34 see: http://legacy.python.org/dev/peps/pep-0435/ and the Python34 manual

Member Avatar for Tcll
0
269
Member Avatar for D3N9

John Zelle teaches Python at Wartburg College. He is the author of graphics.py used by a number of schools instead of Tkinter Get the graphics module (a thin wrapper for Tkinter) here ... http://mcsp.wartburg.edu/zelle/python/graphics.py also has a nice documentation ... http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf

Member Avatar for Schol-R-LEA
0
234
Member Avatar for vegaseat

The story has it that a few hundred years ago the ruler of a big country wanted to reward the creator of the chess game. The creator of the game simply wanted one grain of rice put on the first square of the chessboard, two grains on the second, then …

Member Avatar for vegaseat
2
895
Member Avatar for winecoding

My current encoding comes up 'cp1252' because I am using the Anaconda3 Python system. It might be best to set it in open() if you need a specific encoding.

Member Avatar for vegaseat
0
400
Member Avatar for vegaseat

Again, calculate the minimum number of bills or coins required for a given amount of money (change). This time we will use a Go map instead of a csv string converted to a structure.

0
429
Member Avatar for vegaseat

This Go snippet calculates the minimum number of bills or coins needed for a given amount of money (change) requested. The program also gives the denomination and number. US curency is used in this example, but can be changed to another currency.

1
476
Member Avatar for fonzali

Since Entry() gives a string, you can ask the user to separate the numbers with a semicolon. Then you can split the string and process it accordingly. For example ... eget = "123;321;456;2.45;12.8" numbers = [float(x) for x in eget.split(';')] print(numbers) print(sum(numbers))

Member Avatar for fonzali
0
4K
Member Avatar for jolio5

Python is designed for readable code. If you want to write your entire code on one line, you have to pick another language. You can do it C.

Member Avatar for vegaseat
0
180
Member Avatar for vulcano224

Here is a generic program templet that takes 2 numbers, checks the input, processes the entered data and shows the result. The Tkinter GUI toolkit is used. You can easily add additional inputs and change the processing to whatever you want ... [code]# a general Tkinter program to enter two …

Member Avatar for minyechil
0
425
Member Avatar for vegaseat

Another translation of one of my Python snippets. This function will return a slice of consecutive prime numbers from 2 to a given value limit. In Go the 'int' type (int32) will go as high as 2147483647, but you can replace 'int' with 'uint64' and go as high as 18446744073709551615.

1
1K
Member Avatar for Teeban Jay

Remove lines 124 to 134, you already have declared these variables in lines 27 to 37. Move lines 27 to 37 into your main program below the win1() line to make those variables global. Variables declared inside a function are local to that function.

Member Avatar for vegaseat
0
226
Member Avatar for vegaseat

Generators are rather familiar objects in Python. Generators supply data on demand. Using Go you can create a generator with a goroutine and a channel. Here the goroutine is an anonymous function within a function, simple to implement.

Member Avatar for vegaseat
0
1K
Member Avatar for deonis

Have not used wxPython ever since Python3 came out. I still have Portable Python276 on my flashdrive and found this. Have you tried wxPython's wx.lib.plot.PlotCanvas()? Here is an example ... # using wxPython's wx.lib.plot.PlotCanvas() # to show a line graph of some trig functions # also save graph to an …

Member Avatar for deonis
0
1K
Member Avatar for vegaseat

Another little adventure into Go coding. This time a slice (a Go open ended array) of structures is used as a record for some data processing. For those who miss the ; at the end of a line of code, you can use them, but the lexer of the compiler …

Member Avatar for vegaseat
1
3K
Member Avatar for dadaas
Member Avatar for vegaseat

Some folks go on vacation around the Easter holidays, so it would be nice to know when Easter happens in the years ahead. I had this as a Python snippet in my "oldies, but goodies" file and translated it to Go. It was actually quite easy in this case, and …

Member Avatar for vegaseat
0
964
Member Avatar for webecedarian
Member Avatar for vegaseat
0
118
Member Avatar for vjcagay

Here is the popularity of computer languages worldwide, Mar 2015 compared to a year ago ( http://pypl.github.io/PYPL.html ) ... +------+--------------+----------+-------+ | Rank | Language | Share(%) | Trend | +------+--------------+----------+-------+ | 1 | Java | 24.7 | -0.4 | | 2 | PHP | 11.7 | -1.2 | | 3 …

Member Avatar for vegaseat
-1
4K
Member Avatar for vegaseat

This time just a simple example of grading scores (0 - 100) with letters (A - F). Two approaches are presented, one using switch/case in an "on the fly" function, and the other uses the score as an index to a string of letters F through A.

Member Avatar for vegaseat
1
829
Member Avatar for Warrens80

The dentist slipped and hit the tooth above, so I had to pay for five teeth.

Member Avatar for webecedarian
0
223
Member Avatar for bunkus
Member Avatar for vegaseat
0
8K
Member Avatar for vegaseat

Just some interesting applications of the bitwise and (&), or (|) operators. You might find some other uses.

Member Avatar for vegaseat
0
282
Member Avatar for durgaBHAVANI

Here is a typical eaxample ... // // http://www.airspayce.com/mikem/bcm2835/examples.html // #include <bcm2835.h> #include <stdio.h> // Input on RPi pin GPIO 15 #define PIN RPI_GPIO_P1_15 int main(int argc, char **argv) { // If you call this, it will not actually access the GPIO // Use for testing // bcm2835_set_debug(1); if (!bcm2835_init()) …

Member Avatar for vegaseat
0
2K
Member Avatar for Raman_4

# templet of wxPython's # wx.lib.scrolledpanel.ScrolledPanel(parent, id, pos, size, style) # default pos is (0, 0) and default size is (-1, -1) which fills the frame # the scrolled panel is an area on which other controls are placed # that can take more space then the parent frame has …

Member Avatar for vegaseat
0
240
Member Avatar for webecedarian
Member Avatar for advent_geek
0
317
Member Avatar for jeremywduncan

A modification of Henri's approach using dictionary comprehension ... import pprint # write a test file with unique words names = '''\ Paul Peter Sally Frank Jim Sandra Quasimo ''' fname = "names.txt" with open(fname, 'w') as fout: fout.write(names) with open(fname) as fin: name_dict = {name.strip():None for name in fin} …

Member Avatar for Mohammad_19
0
3K
Member Avatar for vegaseat

Reading the content of a web page with a given URL is pretty simple with Go. Here we defer the closing of the response body (at an early point, so we won't later forget) until the program exits.

0
22K
Member Avatar for lapo3399

If you are using Python3 ... ''' den2anybase.py denary to any base (2 to 36) conversion Python3 ''' def den2anybase(number, radix): """ well, most any base with a radix in the range of 2 to 36 given a denary integer number (base 10) return the base radix representation as a …

Member Avatar for vegaseat
0
2K
Member Avatar for tony75

Another way using the slice operator ... s = "f0cbf260e0ca8ec2431089fb393a1c29513aaaa5847d13e8be84760968e64dc6" sx = r"\x" + r"\x".join(s[n : n+2] for n in range(0, len(s), 2)) print(sx)

Member Avatar for EMERSON_1
0
10K
Member Avatar for MustafaScript

PyCharm is a pretty complex IDE for beginners. Why not start with the Idle IDE that comes with Python? Also check out ... http://ninja-ide.org/ Ninja is free

Member Avatar for EMERSON_1
0
439
Member Avatar for jemdev03
Member Avatar for Seher_1

Also take a look at the Python module made for this sort of thing: http://radimrehurek.com/gensim/

Member Avatar for Gribouillis
0
167
Member Avatar for turntomyleft

At first create a folder like **Atest** in your Python directory **C:\Python34** where you can save your newly created Python files. On your Windows machine there should be a file called idle.bat in the folder C:\Python34\Lib\idlelib Double click on idle.bat and the IDE that comes with your Python installation called …

Member Avatar for vegaseat
0
784
Member Avatar for BustACode

There is also an old snippet at ... https://www.daniweb.com/software-development/python/code/444473/a-memoize-decorator-for-python-recursive-functions

Member Avatar for vegaseat
0
1K
Member Avatar for vegaseat
Member Avatar for vegaseat
4
688
Member Avatar for Julie_2

Here is a hint ... data_str_raw = '''\ 76 82 29 29 33 57 91 55 36 35 13 32 40 80 75 94 11 57 75 19''' # write the data to a file fname = "aa_numbers.txt" with open(fname, "w") as fout: fout.write(data_str_raw) # read the data back in …

Member Avatar for vegaseat
0
187
Member Avatar for python1

In your case it might be simpler to hard code the thing ... [code=python]filepath = "C/myfolder/myfile.txt" fout = open(filepath, "w") [/code]

Member Avatar for Parikshit_1
0
44K
Member Avatar for Warrens80

Even Windows8.1 is already outdated as Windows10 comes along. It is in Microsoft's interest to end supporting the older Windows versions. There is money to be made!

Member Avatar for vegaseat
0
327
Member Avatar for vegaseat

Use Google's modern Go language (aka. golang) to convert a denary number (base 10) to a roman numeral. Just a good exercise to explore Go's map, slice, sort and for loop features. Note that in Go the **:=** is shorthand for assigning a type (by inference) and a value to …

2
596
Member Avatar for snippsat
Member Avatar for vegaseat
3
173
Member Avatar for vegaseat

Just an example of a persistent list class that could have interesting applications in data mining.

1
681
Member Avatar for BustACode
Member Avatar for vegaseat
0
236
Member Avatar for Dom_1

The End.