Re: [Tutor] Hash map and dictionaries

2013-12-01 Thread Devin Jeanpierre
On Sun, Dec 1, 2013 at 7:40 AM, Reuben wrote: > Hi > > Question 1: > - > I would like to know the concept of hash map. Additionally, I got to know > that hash maps are equivalent to dictionaries in python. > > I would like to understand the relationship between dictionaries and ha

Re: [Tutor] Loop over floating point values

2013-12-01 Thread eryksun
On Mon, Dec 2, 2013 at 1:28 AM, Amit Saha wrote: > Indeed, that's a good point. Surprisingly, C does it just fine: > > # include > > int main(int argc, char **argv) > { > float x = 0.0; > while(x<1) > { > x += 0.1; > printf("%f\n", x); > } > > return 0; > } Python uses

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
On Mon, Dec 2, 2013 at 4:36 PM, Asokan Pichai wrote: > On Mon, Dec 2, 2013 at 11:58 AM, Amit Saha wrote: >> >> On Sun, Dec 1, 2013 at 7:26 PM, Steven D'Aprano >> wrote: >> > On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote: >> >> Hello, >> >> >> >> Much to my disbelief, I realized I had

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
On Sun, Dec 1, 2013 at 7:47 PM, spir wrote: > On 12/01/2013 10:03 AM, Amit Saha wrote: >> >> Hello, >> >> Much to my disbelief, I realized I hadn't written a program in Python >> as far as I can recall which required me to do something like this, in >> psuedocode: >> >> x = 0.1 >> >> for i = 0 to

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
On Sun, Dec 1, 2013 at 7:14 PM, Dominik George wrote: > Hi, > >> - Do not create a list of the floating point values as i=[0.01, 0.02, >> 0.03..] - either like that or by using a suitable mathematical formula >> combined with a list comprehension > > You could simply write your own version of xran

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
On Sun, Dec 1, 2013 at 7:26 PM, Steven D'Aprano wrote: > On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote: >> Hello, >> >> Much to my disbelief, I realized I hadn't written a program in Python >> as far as I can recall which required me to do something like this, in >> psuedocode: >> >> x

Re: [Tutor] truncated dictionary return

2013-12-01 Thread richard kappler
Would something like if len(dict) = 8 return d else continue work? On Sun, Dec 1, 2013 at 8:54 PM, richard kappler wrote: > Now I'm completely lost. While opening the serial port outside the > function sounds like a good idea, I'm thinking that might not work unless I > am mistaken. Th

Re: [Tutor] truncated dictionary return

2013-12-01 Thread richard kappler
Now I'm completely lost. While opening the serial port outside the function sounds like a good idea, I'm thinking that might not work unless I am mistaken. The sensorRead function once it's called would then basically own the serial port barring other traffic, yes? That won't work as the same seria

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Mark Lawrence
On 01/12/2013 18:02, Reuben wrote: Thanks everyone for all the replies. No problem but please don't top post, it makes following long threads particularly difficult, thanks. -- Python is the second best programming language in the world. But the best has yet to be invented. Christian Tismer

Re: [Tutor] truncated dictionary return

2013-12-01 Thread spir
On 12/01/2013 08:28 PM, richard kappler wrote: I have a script that reads sensor values gathered by an Arduino board from serial as a dictionary, said values to later be used in the AI for Nav & Control. Here's the script: #!/usr/bin/python def sensorRead(): import serial from time im

Re: [Tutor] empty delimiters, and None

2013-12-01 Thread ugajin
Well, yes. I find can indeed use;locale.setlocale(locale.LC_ALL) thanks! In addition to locale.setlocale(locale.LC_ALL, None) I found I can also use; locale.setlocale(locale.LC_ALL, 'en_GB') The question remains, why does; locale.setlocale(locale.LC_ALL, '') fail, especially if it is good pr

[Tutor] Fwd: empty delimiters, and None

2013-12-01 Thread ugajin
The answer is , yes (to both questions) locale -a does report availability of en_US (and en_US.UTF), C is supported, but C.UTF-8 does not appear in the list. I have tried inserting export LANG="en_GB.UTF.8" as a new line 127. Thanks. -A -Original Message- From: eryksun To: uga...@t

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Reuben
Thanks everyone for all the replies. On Sun, Dec 1, 2013 at 11:29 PM, Joel Goldstick wrote: > > > > On Sun, Dec 1, 2013 at 12:53 PM, Mark Lawrence wrote: > >> On 01/12/2013 17:40, eryksun wrote: >> >>> On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano >>> wrote: >>> On Sun, Dec 01, 2013 at 0

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Reuben
I mean occurrence of 2 from numbers 1 to 100. The number could be the first digit or second digit in a two digit number..for e.g. In number 21 it appears as first digit. For number 92 it appears as second digit On 01-Dec-2013 2:45 PM, "Steven D'Aprano" wrote: > On Sun, Dec 01, 2013 at 11:20:02AM

[Tutor] Hash map and dictionaries

2013-12-01 Thread Reuben
Hi Question 1: - I would like to know the concept of hash map. Additionally, I got to know that hash maps are equivalent to dictionaries in python. I would like to understand the relationship between dictionaries and hash map better. Question 2: -- It is also sa

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Reuben
I tried it with the python interpreter as mentioned below: test@test-Inspiron-1564:~/learn$ python Python 2.7.4 (default, Apr 19 2013, 18:28:01) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> On Sun, Dec 1, 2013 at 7:50 PM, Steven D'Apra

Re: [Tutor] Loop over floating point values

2013-12-01 Thread spir
On 12/01/2013 10:03 AM, Amit Saha wrote: Hello, Much to my disbelief, I realized I hadn't written a program in Python as far as I can recall which required me to do something like this, in psuedocode: x = 0.1 for i = 0 to x step 0.01 # do something with i end i Simply stated, I want to start

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread spir
On 12/01/2013 06:50 AM, Reuben wrote: Hi, How can we write a logic for detecting the number 2 in range from 1 to 100 Do you mean: if 2 in numbers: ? Also for a more general solution, think at the very nice function any(bools), in combination with a generator comprehension:

Re: [Tutor] Alternatives to append() for "growing" a list

2013-12-01 Thread spir
On 12/01/2013 05:32 AM, Amit Saha wrote: Hello, I was told by someone (as a comment) that a code snippet such as this "would make Pythonistas talk my ear off about how evil the append()" function is: mylist = [] mylist.append(1) # a number of times over I have some ideas that on an append()

Re: [Tutor] truncated dictionary return

2013-12-01 Thread Paul Simon
"Wolfgang Maier" wrote in message news:loom.20131201t230651-...@post.gmane.org... > richard kappler gmail.com> writes: > >> >> I have a script that reads sensor values gathered by an Arduino board >> from > serial as a dictionary, said values to later be used in the AI for Nav & > Control. Here

Re: [Tutor] truncated dictionary return

2013-12-01 Thread Wolfgang Maier
Hi again, think I spotted the problem now: you’re setting up your connection everytime you enter the function (with the serial.Serial call), but I guess you’re calling that function repeatedly to retrieve lines. That’s wrong and means you could loose data that was sent while you weren’t listening.

Re: [Tutor] truncated dictionary return

2013-12-01 Thread Wolfgang Maier
richard kappler gmail.com> writes: > > I have a script that reads sensor values gathered by an Arduino board from serial as a dictionary, said values to later be used in the AI for Nav & Control. Here's the script: > #!/usr/bin/python > > > def sensorRead(): >     import serial >     from time

[Tutor] truncated dictionary return

2013-12-01 Thread richard kappler
I have a script that reads sensor values gathered by an Arduino board from serial as a dictionary, said values to later be used in the AI for Nav & Control. Here's the script: #!/usr/bin/python def sensorRead(): import serial from time import sleep sensors = {} sensors = dict.fro

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Mark Lawrence
On 01/12/2013 17:59, Joel Goldstick wrote: On Sun, Dec 1, 2013 at 12:53 PM, Mark Lawrence mailto:breamore...@yahoo.co.uk>> wrote: On 01/12/2013 17:40, eryksun wrote: On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano mailto:st...@pearwood.info>> wrote: On Sun, Dec

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Joel Goldstick
On Sun, Dec 1, 2013 at 12:53 PM, Mark Lawrence wrote: > On 01/12/2013 17:40, eryksun wrote: > >> On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano >> wrote: >> >>> On Sun, Dec 01, 2013 at 02:57:33PM +0530, Reuben wrote: >>> I mean occurrence of 2 from numbers 1 to 100. The number could be the

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Mark Lawrence
On 01/12/2013 17:40, eryksun wrote: On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano wrote: On Sun, Dec 01, 2013 at 02:57:33PM +0530, Reuben wrote: I mean occurrence of 2 from numbers 1 to 100. The number could be the first digit or second digit in a two digit number..for e.g. In number 21 it

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread eryksun
On Sun, Dec 1, 2013 at 6:14 AM, Steven D'Aprano wrote: > On Sun, Dec 01, 2013 at 02:57:33PM +0530, Reuben wrote: >> I mean occurrence of 2 from numbers 1 to 100. The number could be the >> first digit or second digit in a two digit number..for e.g. In number 21 it >> appears as first digit. For n

Re: [Tutor] Alternatives to append() for "growing" a list

2013-12-01 Thread eryksun
On Sun, Dec 1, 2013 at 2:04 AM, Steven D'Aprano wrote: > might trigger a re-size. If the list needs to increase, it will double > in size up to some maximum, then it will grow by a smaller amount. The > purpose of this is that *on average* appending to the list will take a > fixed amount of time.

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Steven D'Aprano
On Sun, Dec 01, 2013 at 08:43:46AM -0500, bruce wrote: > hmm... > > two questions. (new to cmdline py) > > tried typing in what was typed in above in the python shell: > > for i in range(1, 101): > print "2" in str(i) > > this did nothing.. Curious. Which Python shell did you use? I would

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Mark Lawrence
On 01/12/2013 05:50, Reuben wrote: Hi, How can we write a logic for detecting the number 2 in range from 1 to 100 Regards, Reuben Paper and pen or pencil should be perfectly adequate for this task. Alternatively, open an editor, type some code, run it, if you have problems ask another que

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Mark Lawrence
On 01/12/2013 09:14, Dominik George wrote: Hi, - Do not create a list of the floating point values as i=[0.01, 0.02, 0.03..] - either like that or by using a suitable mathematical formula combined with a list comprehension You could simply write your own version of xrange that does it, as a g

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Steven D'Aprano
On Sun, Dec 01, 2013 at 02:57:33PM +0530, Reuben wrote: > I mean occurrence of 2 from numbers 1 to 100. The number could be the > first digit or second digit in a two digit number..for e.g. In number 21 it > appears as first digit. For number 92 it appears as second digit The most efficient way i

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Steven D'Aprano
On Sun, Dec 01, 2013 at 07:03:15PM +1000, Amit Saha wrote: > Hello, > > Much to my disbelief, I realized I hadn't written a program in Python > as far as I can recall which required me to do something like this, in > psuedocode: > > x = 0.1 > > for i = 0 to x step 0.01 > # do something with i >

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Steven D'Aprano
On Sun, Dec 01, 2013 at 11:20:02AM +0530, Reuben wrote: > Hi, > > How can we write a logic for detecting the number 2 in range from 1 to 100 2 in range(1, 101) -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription o

Re: [Tutor] Loop over floating point values

2013-12-01 Thread Dominik George
Hi, > - Do not create a list of the floating point values as i=[0.01, 0.02, > 0.03..] - either like that or by using a suitable mathematical formula > combined with a list comprehension You could simply write your own version of xrange that does it, as a generator: def xrange_f(start, stop, st

[Tutor] Loop over floating point values

2013-12-01 Thread Amit Saha
Hello, Much to my disbelief, I realized I hadn't written a program in Python as far as I can recall which required me to do something like this, in psuedocode: x = 0.1 for i = 0 to x step 0.01 # do something with i end i Simply stated, I want to start from say a value, 0 and go upto 0.1 in incr

Re: [Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Amit Saha
Hello, On Sun, Dec 1, 2013 at 3:50 PM, Reuben wrote: > Hi, > > How can we write a logic for detecting the number 2 in range from 1 to 100 You question is unclear. Could you please give more details ? Best, Amit. -- http://echorand.me ___ Tutor mai

Re: [Tutor] Alternatives to append() for "growing" a list

2013-12-01 Thread Amit Saha
On Sun, Dec 1, 2013 at 5:04 PM, Steven D'Aprano wrote: > On Sun, Dec 01, 2013 at 02:32:38PM +1000, Amit Saha wrote: >> Hello, >> >> I was told by someone (as a comment) that a code snippet such as this >> "would make Pythonistas talk my ear off about how evil the append()" >> function is: > > Ther

[Tutor] Occurrence of number 2 in a range from 1 to 100

2013-12-01 Thread Reuben
Hi, How can we write a logic for detecting the number 2 in range from 1 to 100 Regards, Reuben ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor