On 05/20/2013 12:55 PM, Thomas Murphy wrote:
Mitya,
Why is it best in this situation to use range() rather than a while
loop? Curious about best practices for the various iterating
functions. Thanks!
There are a few issues here:
* variable names should be lower case
* for this case it's best t
On 05/20/2013 12:31 PM, Rafael Knuth wrote:
Hello,
>
> I wrote a simple program, and I was expecting that I would get 100
different random numbers. Instead, I am getting 100 times exactly the
same random number. Can anyone advise how I should alter my program?
>
> Thank you!
>
> All the best,
On 05/04/2013 12:13 AM, Jim Mooney wrote:
for num in listOfNumChars:
> num = int(num)
It seems like people learning Python run into this very often.
I think the reason is that in most simple cases, it's easier and more
intuitive to think that the name IS the object:
x = 1
y = 2
print x +
On 04/27/2013 10:21 PM, Jim Mooney wrote:
#Changing a dictionary into a 2-tuple list with the items method
works, as per the
#first example. But using iteritems returns an error - using Py33
dick = {'villain': 'Roderigo', 'hero': 'Othello', 'friend': 'Cassio',
'beauty':'Desdemona'}
dickList = d
On 04/24/2013 10:59 AM, Sydney Shall wrote:
//I am a beginner just learning Python.
I have come across the following usage for the first time.
totalViruses[i] /= float(numTrials)
Does it mean? ; totalViruses[i] = totalViruses[i]/float(numTrials)
--
Sydney
That's exactly right, you can als
On 04/22/2013 09:47 PM, Jim Mooney wrote:
Okay, what am I doing wrong here? I'm generating primes from a list
and getting "list index out of range," but since the for loops
controls the indexes I don't see how that's happening. I thought it
was the list append, but I commented that out and put in
On 04/09/2013 07:50 AM, Najam Us Saqib wrote:
Hi,
>
> This program is killing me, I have been working on it for last 3
hours, I have tried my best but can't make it work, please help me out.
>
> The Problem:
>
> Create a program that flips a coin 100 times and than tells you the
number of tai
On 04/06/2013 06:00 PM, Soliman, Yasmin wrote:
I have two questions on these simple programs:
>
> 1st why does this loop keep repeating after I enter 'Quit'?
>
> import calendar
> m = raw_input(“Enter a year: “)
> while m != “Quit”:
> if calendar.isleap(int(m)):
> print “%d is a leap year” %
On 03/20/2013 09:14 PM, Matthew Johnson wrote:
I recently asked a question on SO:
http://stackoverflow.com/questions/15180767/subset-list-based-on-value-of-dictionary-element
and got very confused when trying to generalise the answer.
The problem is as follows:
say i have this list, and would
On 03/18/2013 11:14 PM, Clark, Tristan wrote:
Hi,
I am importing data produced from an external code. The data is
organized into columns. I would like to be able to assign each column
to a variable or array. How would you recommend doing this? I have
been looking into the pickle function, as
On 03/20/2013 02:12 AM, Arijit Ukil wrote:
I am new to python. My intention is to read the file digi.txt and
store in separate arrays all the values of each columns. However, the
following program prints only the last value, i.e. 1350696500.0.
Please help to rectify this.
f = open (/"digi.txt"
On 03/29/2013 07:33 AM, Ghadir Ghasemi wrote:
Hi guys I am trying to create part of a vending machine. The section below is if the user wants to
insert 50p coins. It works but when I entered a non integer like
'dfsdf', the program just broke. Is there a way that the program can
check if the in
On 03/23/2013 12:08 AM, Robert Sjoblom wrote:
Hi list. I'll preface this by saying that I am very grateful for all
> of you, and thank you in advance to anyone that answers.
>
> I'm currently working on a roulette simulator, because it seemed like
> fun. I found out I needed a way to compare tw
On 03/22/2013 11:29 PM, Lolo Lolo wrote:
using a socket im trying to send a message between connections. it was a string and my python
complained:
> "TypeError: must be bytes or buffer, not str" .. so i put a b infront
of the string. now this works fine but the problem is after recieving
this
On 03/22/2013 05:02 AM, miguel.gua...@hushmail.com wrote:
Greetings all!
>
>
> My name is Miguel Guasch, I'm a software tester who's trying to
> slowly get into automation, and eventually (in a couple of years)
> into development. For that, I need to learn. At the moment I'm
> studying computer
On 03/21/2013 10:20 PM, Steven D'Aprano wrote:
On 22/03/13 12:39, Mitya Sirenef wrote:
>
>> You can do it with groupby like so:
>>
>>
>> from itertools import groupby
>> from operator import itemgetter
>>
>> maxDate = "2013-03-2
On 03/21/2013 08:39 PM, Matthew Johnson wrote:
Dear list,
>
> I have been trying to understand out how to use iterators and in
> particular groupby statements. I am, however, quite lost.
>
> I wish to subset the below list, selecting the observations that have
> an ID ('realtime_start') value th
On 03/20/2013 04:21 AM, Peter Otten wrote:
Phil wrote:
On 20/03/13 15:09, Mitya Sirenef wrote:
By the way, you can further simplify it by doing:
def histogram2(s):
return {c: d.get(c,0)+1 for c in s}
That will work in python 3, in python 2 you need:
return dict((c: d.get(c,0
On 03/20/2013 01:09 AM, Mitya Sirenef wrote:
By the way, you can further simplify it by doing:
def histogram2(s):
return {c: d.get(c,0)+1 for c in s}
That will work in python 3, in python 2 you need:
return dict((c: d.get(c,0)+1) for c in s)
Sorry, it should use a comma:
return
On 03/19/2013 10:54 PM, Phil wrote:
Thank you for reading this.
>
> I'm working my way through a series of exercises where the author
only provides a few solutions.
>
> The reader is asked to modify the histogram example so that it uses
the get method thereby eliminating the if and else state
On 03/19/2013 10:54 PM, Phil wrote:
Thank you for reading this.
>
> I'm working my way through a series of exercises where the author
only provides a few solutions.
>
> The reader is asked to modify the histogram example so that it uses
the get method thereby eliminating the if and else state
On 03/16/2013 03:04 PM, ke...@kendy.org wrote:
START = '<'
> END = '>'
>
> def getargs():
> getops()
> if
> in_filename_1 =
> in_filename_2 =
> out_filename_1 =
> out_filename_2 =
> flag1 =
> verbose =
>
> def this():
> open_for_read()
> stuff()
>
> def open_for_read(filename):
> in_filehandle =
On 03/15/2013 05:47 PM, Christopher Emery wrote:
Hi Mitya,
>
> Thank for your example of code, however at this time its well over my
> head and I think its best if I slowly work on a function that provided
> only what I need and then add to it IF it works into it. Yours
> appears to do a whole l
On 03/15/2013 05:01 PM, Christopher Emery wrote:
Hello All,
>
> Okay, I have created a small function that will check to see if a user
> has answered with a Yes, No or other response. If the user puts yes
> or no the function ends, if they put anything but yes or no then the
> function will ask
On 03/14/2013 08:45 PM, Matthew Ngaha wrote:
thanks guys ive finally got it working. even though i didnt use the
flag due to invalid syntax i realized since i was getting no errors i
wasnt actually doing anything wrong. My mistake was i removed the
ememy ship but for some reason forgot to remove
On 03/14/2013 08:08 PM, Matthew Ngaha wrote:
One good approach is to have a separate function or method with
>> both loops:
>>
>> def attack(self, Enemy):
>>
>> for missile in self.missiles:
>> for rect in Enemy.rects:
>> if QPoint(missile.x + 5, missile.y) in rect:
>> explosion = Explosion(rec
On 03/14/2013 06:38 PM, Matthew Ngaha wrote:
i cant seem to break out of this loop. let me explain the variables you see:
>
> Enemy.ships = [] #an Enemy class variable that contains enemy ships
> self.missiles = [] an instance variable that appends how many Visible
> missiles my ship has fired
On 03/14/2013 07:28 AM, taserian wrote:
Since the identifier and the item that you want to keep are on different lines, you'll need to set
a "flag".
>
> with open(filename) as file:
>
> scanfile=file.readlines()
>
> flag = 0
>
> for line in scanfile:
>
> if line[0:6]=='COMPND' and 'FAB FRAGMENT
On 03/10/2013 08:16 PM, Dave Friedman wrote:
Hi all,
>
> I'm teaching myself Python in part with Google's course, and one of
the exercises is to sort a list of tuples by the last element.
> e.g.: a list [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields [(2, 2), (1,
3), (3, 4, 5), (1, 7)].
>
> My ans
On 03/09/2013 08:39 PM, Mark Lybrand wrote:
I am working through the Django tutorial and I have come across some syntax I am unfamiliar with. From
the context it makes perfect sense what it does, but I haven't seen it
before and was wondering if it is documented anywhere (BTW I see other
examp
On 02/23/2013 09:40 PM, Matthew Johnson wrote:
For the sake of those who finds this thread -- the date / value pairs
> can be printed by the following:
>
> import fred
>
> fred.key(fredKey)
>
> gnpObvs = fred.observations('GNPCA')
>
> for i in range(1, len(gnpObvs['observations']['observation']
On 02/23/2013 04:56 PM, Matthew Johnson wrote:
Hi,
I am trying to make a move from excel to python. My main need is
economic data -- to do economic analysis.
I have found the FRED package, and appear to have connected to the St
Louis Fed's FRED and downloaded some data, but i'm not sure what to
On 02/22/2013 09:11 PM, Rohit Mediratta wrote:
Hi All,
> I want to reload my Module after I fix bugs and want to instantiate
an object of a class contained in this module.
>
> Heres the pseudo code of what I want to do:
>
> def rerun(testBlock) :
> op = testBlock.split('.')
> module = op[0] ; c
On 02/22/2013 04:26 PM, Jim Byrnes wrote:
I am cleaning up my code and have a number of sqlite3 execute statements that extend far past 80
characters.
>
> From my reading implicit line joining with (), [] or {} seems to be
the preferred method, but
>
> cur.execute('SELECT Account FROM pwds WH
On 02/11/2013 12:14 AM, neubyr wrote:
> I have a text file with each line in following format:
>
> Book Name, Author Name, Genre, Publication Date
>
> I would like to perform following queries on this file:
> * Get all books written by an author
> * Remove all books of an author
> * Get informa
On 02/09/2013 02:01 AM, neubyr wrote:
> I am learning Python 2.7 classes and objects. It seems like
attributes (data attributes and methods) can be added to a class/object
even after it's first declaration. For example,
>
>
> class A(object):
> def __init__(self,arg):
> self.val1 = arg
>
> a
On 02/01/2013 11:31 PM, Scurvy Scott wrote:
> Steve-
> thanks a lot for showing me the if __name__ = main part
> I've often wondered how it was used and it didn't make sense until I
> saw it in my own code if that makes any sense.
> Also appreciate the help on the "instructional" side of things
On 01/28/2013 03:19 PM, Dave Wilder wrote:
> On 28 January 2013 2:44, : Oscar Benjamin
[mailto:oscar.j.benja...@gmail.com wrote:
>
> Please post in plain text (not html) as otherwise the code gets
screwed up.
> ...
>
> Some people like to use regexes for everything. I prefer to try
string m
On 01/23/2013 06:13 PM, Alan Gauld wrote:
On 23/01/13 03:08, Mitya Sirenef wrote:
>
>> To make the change you need, use list comprehension to make sums of all
>> rows, sort it (using list sort method); iterate over it using
>> enumerate() and print out "employee
On 01/22/2013 10:34 PM, Dave Angel wrote:
On 01/22/2013 10:08 PM, Mitya Sirenef wrote:
>> On 01/22/2013 09:52 PM, anthonym wrote:
>>> Hello All,
>> >
>> > I originally wrote this program to calculate and print the employee
>> > with the most hours wo
On 01/22/2013 09:52 PM, anthonym wrote:
Hello All,
>
> I originally wrote this program to calculate and print the employee
> with the most hours worked in a week. I would now like to change this
> to calculate and print the hours for all 8 employees in ascending
> order.
>
> The employees are na
On 01/16/2013 04:22 PM, 3n2 Solutions wrote:
Say I have a text file (example below) that has multiple records with
the same format but not always the same number of lines. Each record
is separated by the line that starts with “Examining file” as in below
example. If you notice, the 3D Val is not
On Mon 14 Jan 2013 10:14:24 PM EST, DoanVietTrungAtGmail wrote:
Dear tutors
In learning about the __call__ magic method, in the code below I
deliberately omitted __call__ and, as expected, I got the error
message "TypeError: 'Test' object is not callable". But I am surprised
that the print state
On 01/11/2013 04:32 PM, Dave Angel wrote:
On 01/11/2013 02:41 PM, Jan Riechers wrote:
>> On 10.01.2013 19:50, Mitya Sirenef wrote:
>>> On 01/10/2013 09:06 AM, richard kappler wrote:
>>>
>>> class Tree(object):
>>> height = 0
>>>
>>>
On 01/11/2013 02:41 PM, Jan Riechers wrote:
On 10.01.2013 19:50, Mitya Sirenef wrote:
>> On 01/10/2013 09:06 AM, richard kappler wrote:
>>
>> class Tree(object):
>> height = 0
>>
>> def grow(self):
>> self.height += 1
>>
>> You may have a
On 01/10/2013 09:06 AM, richard kappler wrote:
Class is still something I struggle with. I think I'm finally starting
> to get my head wrapped around it, but the discussion in a different
> thread has sparked a question. First, please check my understanding:
> A class creates objects, it's lik
On Wed 09 Jan 2013 09:26:15 PM EST, Ed Owens wrote:
I'm working my way through Chun's book "Core Python Applications
Programming" and can't get one of the examples to actually work. In
trying to analyze the problem (good learning approach) I had troubles
understanding the interactions between th
On Wed 09 Jan 2013 01:27:26 PM EST, richard kappler wrote:
I have a sort of a dictionary resulting from psutil.disk_usage('/')
that tells me info about my hard drive, specifically:
usage(total=147491323904, used=62555189248, free=77443956736,
percent=42.4)
I'm having a bit of a brain fudge here
On Wed 09 Jan 2013 01:56:20 AM EST, ken brockman wrote:
I was looking through some lab material from a computer course offered
at UC Berkeley and came across some examples in the form of questions
on a test about python.
1 and 2 and 3
answer 3
I've goggled it till i was red in the fingers, but t
On Tue 08 Jan 2013 08:07:57 PM EST, Alan Gauld wrote:
On 05/01/13 01:27, Nathaniel Huston wrote:
def deal(quantity):
hand = []
for cards in range(0, quantity):
hand.append(deck.pop())
return hand
> #we find that the global deck has been modified within the deal()
> fu
On 01/04/2013 06:34 AM, Ghadir Ghasemi wrote:
H I wanted to create a program called vending machine and I wondered if you could do it so I can find
out how to do it.
> Here is how it should work like:
>
> A food vending machine accepts 10p, 20p, 50p and £1 coins.
> One or more coins are inserte
On 12/30/2012 06:59 PM, Brandon Merritt wrote:
I am having trouble figuring out a solution after a couple hours now
of playing with the code. I'm trying to make a latin square using the
code below:
scaleorder = int(raw_input('Please enter a number for an n*n square: '))
topleft = int(raw_inp
On 12/23/2012 08:03 PM, Tom Tucker wrote:
Python Gurus,
I got a question for ya. Below I have three instance variables
(self.A, self.B, etc). How can I use the below
for loop for A, B, C to also call those instance variables?
Example
###
.
.
self.A = 1
self.
On 12/23/2012 02:48 AM, Mario Cacciatore wrote:
Hey everyone,
>
> I am having a very hard time understanding the list comprehension
syntax. I've followed the docs and could use some guidance from the fine
folks here to supplement my findings. If someone wouldn't mind replying
back with an exa
On 12/19/2012 01:19 AM, Brandon Merritt wrote:
Sorry, I am just so confused and aggravated as to why this won't work
- why doesn't it print out the whole list? :
number = raw_input('Enter a 7-unit number: ')
for i in number:
count = []
count.append(i)
print count
>>> Enter a 7-unit n
On 12/19/2012 12:40 AM, Brandon Merritt wrote:
I feel silly, but I'm having the darndest time trying to figure out
why this for counter won't work. I know that there is the count method
for the string class, but I was just trying to do it the syntactical
way to prove myself that I know the very
On 12/18/2012 08:05 PM, Gina wrote:
I have Python version 3.
when the program begins, it prints out the main menu and then asks you
for your choice - just like it is supposed to
you enter your choice, and the next menu pops up, and below the menu
it says "None" on the line before your next choi
On 12/17/2012 12:00 AM, boB Stepp wrote:
On Sun, Dec 16, 2012 at 10:41 PM, Mitya Sirenef wrote:
>
>> What would you want to happen for int("10.5")? If 10.0 was accepted,
>> it would be consistent to accept 10.5, too.
>
> I was expecting int("10.5")
On 12/16/2012 11:19 PM, boB Stepp wrote:
int('10.0')
> Traceback (most recent call last):
> File "", line 1, in
> ValueError: invalid literal for int() with base 10: '10.0'
int("10")
> 10
>
> It is apparent that int() does not like strings with floating-point
> formats. None of my books (a
59 matches
Mail list logo