4,305 Posted Topics
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 … | |
Re: 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/ | |
Re: Sharp eye! Too bad that the compiler does not catch an obvious mistake like this. :) if(fp==NULL) ; // do nothing is correct code | |
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 ... … | |
Just a couple of number tricks to check Go's mathematical abilities. If you have more, let's show them here. | |
Re: 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 | |
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 … | |
Re: Module enum is new in Python34 see: http://legacy.python.org/dev/peps/pep-0435/ and the Python34 manual | |
Re: 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 | |
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 … | |
Re: 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. | |
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. | |
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. | |
Re: 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)) | |
Re: 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. | |
Re: 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 … | |
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. | |
Re: 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. | |
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. | |
Re: 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 … | |
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 … | |
Re: What happens if you leave **.string** off? Also use print(proxy) | |
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 … | |
Re: I used Abiword in my diaper days. Now it's all Open Office. | |
![]() | Re: 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 … |
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. | |
![]() | Re: The dentist slipped and hit the tooth above, so I had to pay for five teeth. |
Re: Start with: http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm#Java | |
Just some interesting applications of the bitwise and (&), or (|) operators. You might find some other uses. | |
Re: 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()) … | |
Re: # 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 … | |
Re: Eventually security issues will make the web more restrictive. | |
Re: 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} … | |
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. | |
Re: 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 … | |
Re: 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) | |
Re: 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 | |
Re: Also take a look at the Python module made for this sort of thing: http://radimrehurek.com/gensim/ | |
Re: 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 … | |
Re: There is also an old snippet at ... https://www.daniweb.com/software-development/python/code/444473/a-memoize-decorator-for-python-recursive-functions | |
This shows the application of a Memoize decorator to speed up recursive functions in Python. | |
Re: 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 … | |
Re: In your case it might be simpler to hard code the thing ... [code=python]filepath = "C/myfolder/myfile.txt" fout = open(filepath, "w") [/code] | |
![]() | Re: 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! |
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 … | |
Just an example of a persistent list class that could have interesting applications in data mining. | |
Re: The problem with Small Basic is that it has a goto but no comefrom. | |
The End.