Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
You forgot to include the list. So I'm forwarding it now, with new remarks. On 07/20/2012 01:47 AM, wolfrage8...@gmail.com wrote: > On Fri, Jul 20, 2012 at 12:33 AM, Dave Angel wrote: > >> On 07/19/2012 05:55 PM, Prasad, Ramit wrote: I am not sure how to answer that question because all fi

[Tutor] string to binary and back... Python 3

2012-07-19 Thread wolfrage8...@gmail.com
On Fri, Jul 20, 2012 at 12:33 AM, Dave Angel wrote: > On 07/19/2012 05:55 PM, Prasad, Ramit wrote: > >> I am not sure how to answer that question because all files are binary, > >> but the files that I will parse have an encoding that allows them to be > >> read in a non-binary output. But my p

[Tutor] Join email list

2012-07-19 Thread Lily Tran
___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Invalid Token Problem

2012-07-19 Thread Ross Wilson
On 20/07/12 10:45, Dave Angel wrote: On 07/19/2012 08:36 PM, Osemeka Osuagwu wrote: ... 99 ninety nine 100 onehundred 101 one hundred and one 102 one hundred and two 103 one hundred and three 104 one hundred and four 105 one hundred and five 106 one hundred and six 107 one hundred and seven 108

Re: [Tutor] Invalid Token Problem

2012-07-19 Thread Dave Angel
On 07/19/2012 08:36 PM, Osemeka Osuagwu wrote: > ... > 99 ninety nine > 100 onehundred > 101 one hundred and one > 102 one hundred and two > 103 one hundred and three > 104 one hundred and four > 105 one hundred and five > 106 one hundred and six > 107 one hundred and seven > 108 > > Traceback (mos

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 5:32 PM, Jordan wrote: > > I am not sure how to answer that question because all files are binary, > but the files that I will parse have an encoding that allows them to be > read in a non-binary output. But my program will not use the in a > non-binary way, that is why I p

[Tutor] Invalid Token Problem

2012-07-19 Thread Osemeka Osuagwu
Hi folks, I've been trying to convert numbers from digits to words, I wrote the following code; units = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] teens = ['eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'] tens = [

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alexander Q.
On Thu, Jul 19, 2012 at 4:21 PM, Dave Angel wrote: > On 07/19/2012 06:58 PM, Alexander Q. wrote: > > I have this little program that is supposed to calculate how many > diagonals > > a polygon of x sides has, but it does not return what I have in the > > "return" part of the function when I call

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alan Gauld
On 20/07/12 00:17, Prasad, Ramit wrote: def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i in range(num_sides - 3): ans = ans + i return (((var - 3)*2) + ans) num_sides = (int(raw_input("Enter sides: "))) num_diag(num_sides) NameError:

[Tutor] Creating a dictionary on user filter

2012-07-19 Thread Mike Nickey
Hi All, I have a few lists that I'm trying to put into a dictionary based on which list the user wants to use as a filter. If the user selects 1 the the dictionary would be created using the first list as the keys and the secondary items as the values. If the user selects 2, the dictionary would b

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Dave Angel
On 07/19/2012 06:58 PM, Alexander Q. wrote: > I have this little program that is supposed to calculate how many diagonals > a polygon of x sides has, but it does not return what I have in the > "return" part of the function when I call it. Here is the code: > > def num_diag(var): > ans = 0 > if

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Emile van Sebille
On 7/19/2012 3:58 PM Alexander Q. said... I have this little program that is supposed to calculate how many diagonals a polygon of x sides has, but it does not return what I have in the "return" part of the function when I call it. Here is the code: def num_diag(var): ans = 0 if var <= 3:

Re: [Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Prasad, Ramit
> I have this little program that is supposed to calculate how many diagonals a > polygon of x sides has, but it does not return what I have in the "return" > part of the function when I call it. Here is the code: > > def num_diag(var): > ans = 0 > if var <= 3: > print("No diagonals.") >

Re: [Tutor] re 33.116

2012-07-19 Thread Emile van Sebille
On 7/19/2012 4:10 PM Emile van Sebille said... I found ~200k files in /var/log all but 227 look like: Sorry -- my bad. Emile ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/list

[Tutor] re 33.116

2012-07-19 Thread Emile van Sebille
I found ~200k files in /var/log all but 227 look like: list_boxes.day.1.gz.1.gz.1.gz.3.gz.1.gz.1.gz.2.gz.1.gz.1.gz.2.gz.1.gz list_boxes.day.1.gz.1.gz.1.gz.3.gz.1.gz.1.gz.2.gz.1.gz.1.gz.2.gz.1.gz.1.gz list_boxes.day.1.gz.1.gz.1.gz.3.gz.1.gz.1.gz.2.gz.1.gz.1.gz.2.gz.1.gz.1.gz.1.gz list_boxes.day.1.

[Tutor] Calling a function does not return what I want it to return

2012-07-19 Thread Alexander Q.
I have this little program that is supposed to calculate how many diagonals a polygon of x sides has, but it does not return what I have in the "return" part of the function when I call it. Here is the code: def num_diag(var): ans = 0 if var <= 3: print("No diagonals.") else: for i i

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 05:55 PM, Prasad, Ramit wrote: >> I am not sure how to answer that question because all files are binary, >> but the files that I will parse have an encoding that allows them to be >> read in a non-binary output. But my program will not use the in a >> non-binary way, that is why I pl

Re: [Tutor] check against multiple variables

2012-07-19 Thread Steven D'Aprano
Selby Rowley-Cannon wrote: I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. I doubt that very much. This entire question seems like a remarkable case of premature optimization. Start wi

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> I am not sure how to answer that question because all files are binary, > but the files that I will parse have an encoding that allows them to be > read in a non-binary output. But my program will not use the in a > non-binary way, that is why I plan to open them with the 'b' mode to > open them

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 10:48 PM, Prasad, Ramit wrote: OK. I am using one time pads to XOR data, but the one time pads (keys) are very large numbers, converting them to binary increases their size exponentially, which allows me to get more XORing done out of a single >>> You want

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > bin_data = [ bin(ord(char)).split('b')[1].zfill(8) for char in data ] > > bin_string = ''.join(bin_data) > > bin_list = [ chr( int(char, 2) ) for char in bin_data ] > Thank you exactly what I was looking for! > > > > I am not really sure what you are getting at with XOR and one time > > padding

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/18/2012 05:07 PM, Jordan wrote: > OK so I have been trying for a couple days now and I am throwing in the > towel, Python 3 wins this one. I should have paid more attention to this the first time. Clearly you don't want help. -- DaveA ___ Tut

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> >> > >> > >> OK. I am using one time pads to XOR data, but the one time pads (keys) > >> are very large numbers, converting them to binary increases their size > >> exponentially, which allows me to get more XORing done out of a single > > You want to explain this impossibility of increasing siz

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
Sorry, I am not sure why Thunderbird is stripping the spaces, may have something to do with a plug-in that I have installed, I will have to look into it. On 07/19/2012 10:41 PM, Prasad, Ramit wrote: > Sure, this makes perfect sense to me :) (adding indent) > > for char in data: > bin_data += b

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 10:04 PM, eryksun wrote: > On Thu, Jul 19, 2012 at 3:08 PM, Jordan wrote: > I'm not an expert with cryptography, but here's a simple XOR example: from itertools import cycle text = b'Mary had a little lamb.' key = b'1234' cypher = bytes(x^y for x,y in zip(text,

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > bin(integer).split('b')[1].zfill( multiple_of_eight ) > OK so using this: Hopefully my copy paste works this time. > > bin_data = '' > > for char in data: > > bin_data += bin(ord(char)).split('b')[1].zfill(8) > > print(bin_data) > > bin_list = [bin_data[x:x + 2] for x in range(0, len(bin_d

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 09:53 PM, Dave Angel wrote: > On 07/19/2012 03:19 PM, Jordan wrote: >> >> >> OK. I am using one time pads to XOR data, but the one time pads (keys) >> are very large numbers, converting them to binary increases their size >> exponentially, which allows me to get more XORing done ou

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 3:08 PM, Jordan wrote: > > size = 8 * max(len(b3), len(b4)) > format(r, "0%db" % size) >> '0011001100110011' > Is this output the output for size rather than the two variables joined > together? Using "format" is useful if you need the string to be

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 09:23 PM, Prasad, Ramit wrote: >> A question I have for the group before I respond is a option that I saw >> that I had earlier was to ord() each element of a string and then bin() >> that number. But since bin() produces a string I could not figure out >> the correct way to attach

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 03:19 PM, Jordan wrote: > > > OK. I am using one time pads to XOR data, but the one time pads (keys) > are very large numbers, converting them to binary increases their size > exponentially, which allows me to get more XORing done out of a single You want to explain this impossibili

Re: [Tutor] check against multiple variables

2012-07-19 Thread Emile van Sebille
On 7/19/2012 12:29 PM Selby Rowley-Cannon said... I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. The 'hash value' will be stored as a variable. I do not want to check it against each singu

[Tutor] check against multiple variables

2012-07-19 Thread Selby Rowley-Cannon
I am using a hash table in a small randomization program. I know that some hash functions can be prone to collisions, so I need a way to detect collisions. The 'hash value' will be stored as a variable. I do not want to check it against each singular hash value, as there will be many; I need a w

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> A question I have for the group before I respond is a option that I saw > that I had earlier was to ord() each element of a string and then bin() > that number. But since bin() produces a string I could not figure out > the correct way to attach two bin() outputs back together again due to > the

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 08:53 PM, Prasad, Ramit wrote: >>> I think your basic problem is too much conversion because you do not >>> understand the types. A string is represented by a series of bytes >>> which are binary numbers. Do you understand the concept behind ASCII? >>> Each letter has a numeric repr

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
A question I have for the group before I respond is a option that I saw that I had earlier was to ord() each element of a string and then bin() that number. But since bin() produces a string I could not figure out the correct way to attach two bin() outputs back together again due to the leading 'b

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
My response is down lower, thank you Wayne. On 07/19/2012 12:52 PM, Wayne Werner wrote: > I'll preface my response by saying that I know/understand fairly > little about > it, but since I've recently been smacked by this same issue when > converting > stuff to Python3, I'll see if I can explain it

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > I think your basic problem is too much conversion because you do not > > understand the types. A string is represented by a series of bytes > > which are binary numbers. Do you understand the concept behind ASCII? > > Each letter has a numeric representation that are sequential. So the > > stri

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 12:46 PM, Dave Angel wrote: > On 07/19/2012 01:41 AM, wolfrage8...@gmail.com wrote: >> On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: > That was just the first line that was not indented. If I thought you > had a one-line while loop, I certainly would have just indented it.

Re: [Tutor] Fwd: string to binary and back... Python 3

2012-07-19 Thread Prasad, Ramit
> > Just to show you your original message contained no indentation > > whatsoever. You might want to check your mail client settings and do > > some experiments to make sure that indentation spaces are let through > > unmolested and not stripped anywhere, otherwise the current little > > brouhaha

Re: [Tutor] Fwd: string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 10:29 AM, Walter Prins wrote: > Hi, > > Just to show you your original message contained no indentation > whatsoever. You might want to check your mail client settings and do > some experiments to make sure that indentation spaces are let through > unmolested and not stripped anywh

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 08:14 AM, Mark Lawrence wrote: > On 19/07/2012 06:41, wolfrage8...@gmail.com wrote: >> On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: >> > > Really? Are you using a forked version of Python that doesn't need > indentation after a while loop, or are you speaking with a forked

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Jordan
On 07/19/2012 12:15 AM, Prasad, Ramit wrote: > I think your basic problem is too much conversion because you do not > understand the types. A string is represented by a series of bytes > which are binary numbers. Do you understand the concept behind ASCII? > Each letter has a numeric representat

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-19 Thread Prasad, Ramit
> I would get a new list as: > > [(0, '3eA', 'Dupont', 'Juliette', '11.0/10.0', '4.0/5.0', '17.5/30.0', > '3.0/5.0', '4.5/10.0', '35.5/60.0'), (1, '3eA', 'Pop', 'Iggy', > '12.0/10.0', '3.5/5.0', '11.5/30.0', '4.0/5.0', '5.5/10.0', > '7.5/10.0', '40.5/60.0')] > > ... from this one: > > [(0, '3eA'

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-19 Thread शंतनू
You may use 'set'. e.g. === >>> x [(1, 2, 3), (1, 1), (2, 2), (1, 1), (2, 2)] >>> set(x) set([(2, 2), (1, 1), (1, 2, 3)]) === On 19-Jul-2012, at 11:03 PM, PyProg PyProg wrote: > Hi all, > > I would get a new list as: > > [(0, '3eA', 'Dupont', 'Juliette', '11.0/10.0', '4.0/5.0', '17.5/30.0', >

Re: [Tutor] suggestion for an editor

2012-07-19 Thread Alan Gauld
On 19/07/12 09:09, Bala subramanian wrote: Friends, At present i write programs using vi editor. I am interested to change to something else. My specific need is that i want to select a portion/small segment of my program (for eg. a nested loop) and then monitor processing time it takes for that

Re: [Tutor] Flatten a list in tuples and remove doubles

2012-07-19 Thread PyProg PyProg
Oh I forgot to mention, with Python 2 (2.7). -- http://ekd.tuxfamily.org http://ekdm.wordpress.com http://glouk.legtux.org/guiescputil http://lcs.dunois.clg14.ac-caen.fr/~alama/blog http://lprod.org/wiki/doku.php/video:encodage:avchd_converter ___ Tutor

[Tutor] Flatten a list in tuples and remove doubles

2012-07-19 Thread PyProg PyProg
Hi all, I would get a new list as: [(0, '3eA', 'Dupont', 'Juliette', '11.0/10.0', '4.0/5.0', '17.5/30.0', '3.0/5.0', '4.5/10.0', '35.5/60.0'), (1, '3eA', 'Pop', 'Iggy', '12.0/10.0', '3.5/5.0', '11.5/30.0', '4.0/5.0', '5.5/10.0', '7.5/10.0', '40.5/60.0')] ... from this one: [(0, '3eA', 'Dupont',

[Tutor] Pragmatic Unicode, or, How do I stop the pain?

2012-07-19 Thread Sander Sweers
https://www.youtube.com/watch?v=sgHbC6udIqc This is a very good talk on Unicode which was done at PyCon US 2012. It helped me a lot to understand the pain. Greets Sander ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription optio

Re: [Tutor] suggestion for an editor

2012-07-19 Thread Wayne Werner
On Thu, 19 Jul 2012, Bala subramanian wrote: Friends, At present i write programs using vi editor. I am interested to change to something else. My specific need is that i want to select a portion/small segment of my program (for eg. a nested loop) and then monitor processing time it takes for

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread eryksun
On Thu, Jul 19, 2012 at 1:41 AM, wolfrage8...@gmail.com wrote: > > I was comparing them but I think I understand how to compare them well, now > I want to convert them both to binary so that I can XOR them together. Thank > you for your time and help Dave, now I need to reply to Ramit. A bytes ob

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-19 Thread Wayne Werner
Just a few notes... On Wed, 18 Jul 2012, Ryan Waples wrote: import glob my_in_files = glob.glob ('E:/PINK/Paired_End/raw/gzip/*.fastq') for each in my_in_files: #print(each) out = each.replace('/gzip', '/rem_clusters2' ) #print (out) INFILE = open (each, 'r')

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Wayne Werner
I'll preface my response by saying that I know/understand fairly little about it, but since I've recently been smacked by this same issue when converting stuff to Python3, I'll see if I can explain it in a way that makes sense. On Wed, 18 Jul 2012, Jordan wrote: OK so I have been trying for a c

Re: [Tutor] string to binary and back... Python 3

2012-07-19 Thread Dave Angel
On 07/19/2012 01:41 AM, wolfrage8...@gmail.com wrote: > On Thu, Jul 19, 2012 at 12:16 AM, Dave Angel wrote: > >> >> I don't get the same error you did. I get: >> >> File "jordan.py", line 13 >> test_int = int(str(test_int) + str(int.from_bytes(os.urandom(1), >> 'big'))) >>^ >> >

Re: [Tutor] suggestion for an editor

2012-07-19 Thread Ranjith Kumar
Try Sublime, On Thu, Jul 19, 2012 at 1:39 PM, Bala subramanian wrote: > Friends, > At present i write programs using vi editor. I am interested to change to > something else. My specific need is that i want to select a portion/small > segment of my program (for eg. a nested loop) and then monito

[Tutor] suggestion for an editor

2012-07-19 Thread Bala subramanian
Friends, At present i write programs using vi editor. I am interested to change to something else. My specific need is that i want to select a portion/small segment of my program (for eg. a nested loop) and then monitor processing time it takes for that portion while i run the program. By this i ho

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-19 Thread Alan Gauld
On 19/07/12 07:00, Steven D'Aprano wrote: def four_lines(file_object): line1 = next(file_object).strip() # Get the next three lines, padding if needed. line2 = next(file_object, '').strip() line3 = next(file_object, '').strip()

Re: [Tutor] Problem When Iterating Over Large Test Files

2012-07-19 Thread Ryan Waples
> I count only 19 lines. yep, you are right. My bad, I think I missing copy/pasting line 20. >The first group has only three lines. See below. Not so, the first group is actually the first four lines listed below. Lines 1-4 serve as one group. For what it is worth, line four should have 1 cha