Note: In Python 2.7 use: `from __future__ import print_function` to use examples. In Python, by default, the key and value pairs in a dictionary are stored as hashes, therefore dictionaries do not retain the order in which values were added, and cannot be ordered. v_Dict ={} v_Dict["First"] = 99 v_Dict["Second"] = 45 v_Dict["Third"] = 234 print(v_Dict) ## {'Second': 45, 'Third': 234, 'First': 99} No order at all. To maintain an ordered dictionary one must use the collection module's "OrderedDict()." Normally one would declare a dictionary to be ordered like so: from collections import OrderedDict v_Dict = OrderedDict() v_Dict["First"] = 99 …

Member Avatar
Member Avatar
+1 forum 3

!USING PYTHON 3.1! Hello DaniWeb! Today I'm going to teach you a cool variable trick that I learned. So here's an example: [CODE] a, b, c = input('?x?x?: ').split('x') [/CODE] Now let's input something like: [CODE] >>> a, b, c = input('?x?x?: ').split('x') ?x?x?: 1x2x3 [/CODE] Now, variable 'a' is set to 1, variable 'b' is set to 2, variable 'c' is set to 3. I hope I explained that well enough. It can be used in various sections. NOTE: Because you used 3 variables, you [B]have[/B] to have three answers divided by the character you split with. If you …

Member Avatar
Member Avatar
+6 forum 11

Here's a simple tutorial on dictionaries in Python: Dictionaries: Dictionaries are similar to other compound types except that they can use any immutable type as an index. One way to create a dictionary is to start with the empty dictionary and add items. The empty dictionary is denoted {}: [CODE]end2sp = {} end2sp[ "one" ] = "uno" end2sp[ "two" ] = "dos"[/CODE] We can print the current value of the dictionary in the usual way: [CODE]print eng2sp # --> { "one":"uno", "two":"dos" }[/CODE] The elements of a dictionary appear in a coma-separated list. Each entry contains an index and a …

Member Avatar
Member Avatar
+5 forum 16

[B]!USING PYTHON 3.1![/B] Hello DaniWeb! Today I'm going to be posting a [B]simple[/B] threading tutorial. First of all, what is threading? Well, threading is just another way of doing a side task without interrupting the main program. Now here's a simple example. Let's say we are going to make a simple program. When the program starts it is going to start a timer, and it will show the time. Now, observe these 2, similar programs. Good version: [CODE] import threading import time threadBreak = False def TimeProcess(): while not threadBreak: print (time.time() - startTime) startTime = time.time() threading.Thread(target = TimeProcess).start() …

Member Avatar
Member Avatar
+3 forum 13

Probably the simplest way to get into multimedia with Python is the webbrowser module. This works with both Windows and Unix systems, and selects the default browser you have installed. But that is not all: if you give it the name of a multimedia file it will select the default viewer or player, at least in Windows systems. An example sound file might look like this: [code=python]import webbrowser # opens .wav file with default wave sound player webbrowser.open("Train.wav") [/code] Whereas to display a bitmap graphics file you would have something like: [code=python]import webbrowser # opens a .bmp file with default …

Member Avatar
Member Avatar
+4 forum 5

Regex is one of the more complicated modules that you can use in python. Once you have learnt it though you can use it many different programming languages, so its a useful tool for using with strings. So first to use regex you must import it [code] import re [/code] This loads the module for us to use. Regex is a module designed to make strings easy to manipulate and is often used to check for correct input. For example [code] r = raw_input("Please enter an email address") [/code] But how do you know without complicated checking that they have …

Member Avatar
Member Avatar
+3 forum 3

The End.