904 Posted Topics
![]() | Re: Why so complicated? Using a similar english dictionary file: [code=python]# mydict.txt has one English word per line # about 74500 in total mydict = open("mydict.txt", "r").readlines() print(mydict[:10]) """my display of some words in mydict --> ['aardvark\n', 'aardvarks\n', 'aaron\n', 'abaci\n', ... ] """ # strip the trailing newline char mydict = … ![]() |
Re: The reason you want to make something private to the class is to keep it from easily spilling out into external code. So pseudo-private will do one good job. Remember it's called private, not secret! | |
Re: Fred walks into the post office one day and sees one middle-aged, balding man standing at the counter methodically placing "Love" stamps on bright pink envelopes with hearts all over them. He then takes out perfume bottle and starts spraying scent all over them. Fred's curiosity gets the better of … | |
Re: Wow, this difficult to read! Why are there so many "you must" in there? | |
Re: [code=python]# staticmethod() and classmethod() # make it easier to call one class method class ClassA(object): def test(this): print this test = staticmethod(test) ClassA.test(4) # 4 class ClassB(object): @classmethod def test(self, this): print this ClassB.test(4) # 4 [/code] See: [url]http://www.techexperiment.com/2008/08/21/creating-static-methods-in-python/[/url] | |
![]() | Re: You may not want to add letters to the list that have zero count. |
Re: [code=python]import os # works on windows nt (also xp and vista) or linux os.system(['clear','cls'][os.name == 'nt']) [/code]If [os.name == 'nt'] is True then this becomes effectively 1. So it picks item at index 1 from the list which is the Windows command 'cls'. If it's False, it becomes 0 and … | |
Re: Did you download the code or retype it manually yourself? There are some errors due to indentations and typos. The return outside function error is really indentation error! | |
Re: Also with Python3 you don't have to use fahrenheit = (9.0 / 5.0) * celsius + 32 you can just use fahrenheit = (9 / 5) * celsius + 32 since '/' is now floating point division and '//' is integer division. | |
Re: Seems to me that you also have to consider the time that re.compile() needs. | |
Re: Some corrections: [code=python]num = 0 mylist = [] while num < 10: num = num + 1 mylist.append(num) print(mylist) for item in mylist: print(item) [/code] ![]() | |
Re: [QUOTE=Kruptein;1019652]Okay that was quit stupid :f[/QUOTE]Asking questions is never stupid! :) | |
Re: This will also trap number exceeding the index: [code=python]import string def numtolet(num): if num > 25: return return string.ascii_uppercase[num] print( numtolet(0) ) # A print( numtolet(5) ) # F print( numtolet(25) ) # Z print( numtolet(26) ) # None [/code] | |
Re: One of the solutions is pretty straight forward, with easy logic: [code=python]list1 = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] list2 = [1,2,3,4,11] list3 = [] # q1 is each sublist in list1 for q1 in list1: # q2 is each item in list2 for q2 in list2: # do not append if sublist is already … | |
Re: Similar to jice's code: [code=python]# simply ignore index zero pos = [' '] * 11 print( pos ) POS = 1 pos[POS] = '->' print( pos ) """my display --> [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', … | |
Re: [QUOTE=kenmeck03;1011443]I need to prompt a user to type in a text file name and then take that file and and count the amount of words in the file. I have this code which counts the words in a file(that may not be "perfectly" written). I cannot figure out how to … | |
Re: [QUOTE=ammalu;1011900]please help me to develop a program in C for the given problems? 1. Read the string and print the first letters of word? 2. Read the array elements and find the greater and smallest after sorting it? 3. Read the string and print the digits and vowels ?[/QUOTE]You are … | |
Re: If this is truly your text file, I feel sorry for you! | |
![]() | Re: I think you need to develop mask of your image to make this work. |
Re: What are you going to do to the user after 3 tries? | |
Re: At least for some time, it would be very nice if people indicated which version of Python they are using. ![]() | |
Re: [QUOTE=jbennet;595814]historically it was the other way around as loads of wemen died in childbirth[/QUOTE]On the other hand, lots of young men died as they were sent off to war. | |
The Python module datetime allows you to calculate the days between two given dates with relative ease. I am using the US date format month/day/year, but you can change that by giving attention to the order of the extracted tuple. | |
The wxPython GUI toolkit has a nice numeric LED widget (LEDNumberCtrl from the wx.gizmos module) that is used here for displaying the current time in very visible 7 segment LED color display. It also shows the application of the time module and wx.Timer(). The code is simple as far as … | |
The FlashWindow component of wxPython will play those nice animated flash files found on the internet. They have file extension .swf usually. | |
The wxPython GUI tool makes it very simple to create nice looking analog clock. The analog clock component was put into simple dialog frame and can be moved about the screen. | |
Re: I can't believe it needs to be that complex! | |
Here we search a Python script file (or other text file) for one certain string, and copy any files containing this string to another folder. | |
Search for a file given its name and the starting search directory. The search is limited to a set depth of subdirectories. Python makes this easy to do. | |
This Python code will search for given filename starting with given directory. It will also search all the subdirectories in the given directory. The search will end at the first hit. | |
Code snippet to show you how to verify exit events from wxPython using dialog window. One event is from menu exit and the other from frame exit (x symbol in corner). | |
This short code shows how to indicate the mouse-over event on wxPython button, similar to the mouse-over in web pages. Button changes colour when mouse pointer is over its area. | |
The myth is around that while loop is faster than the corresponding for loop. I checked it out with Python module timeit, and came to surprising conclusion. This snippet can easily be modified to time any of your functions you write. | |
The program takes text and establishes dictionary of character:frequency. This dictionary is then presented sorted by character. Since it is important to show the most frequent characters, two methods are given to present dictionary sorted by frequency. Should all be very good for learning Python. | |
Do you think that people act demented during full moon nights? This small python program will tell you moon phase of a date you give it, so you can take precautions! | |
Question of wordcount program similar to Unix wc came up in the forum and I worked on a solution. Program shows number of lines, number of words, number of characters and text file's name. Good learning for commandline, file and string handling. | |
| |
The little program allows eye patients to test their color skills. They are given a random color rectangle by the computer and are then asked to match the color as closely as they can using sliders of the three basic colors. An evaluation button examines the closeness of the results. | |
Re: I would be temded to bring the story in from a text file, but than of course you need to distrubute two files. | |
Re: Vegaseat, to keep primes from going over n, replace line s = range(3, n+2, 2) with s = range(3, n+1, 2) Henri | |
This program use a while loop to delete trailing spaces and tabs from a string. It is meant to be more of an example of the application of the while loop. | |
Commonly strings consist of ASCII characters, some are printable, some are in the backgrounds like the bell, carriage return, linefeed, tab and so forth. This code displays a table of ASCII characters and the corresponding decimal value. As always, you are encouraged to learn here. | |
Just a colorful ten second countdown to New Year. Hope you can learn some code from it. | |
My first experience with pointers. Learned how to spell a string foreward and backward using pointers. I hope you can learn too! | |
Re: I do not know anything of BCX, but you make it read interesting. | |
Re: I do not know Python much, but I was taught that you start with Adam and Eve, not one trillion old people! | |
Re: The last time I has seen such odd header files, was in one of Herb Schildt's old books. | |
Re: Twice is better? You must be shiddin us! |
The End.