I have a particular date time format I use for making entries in various
logs I maintain, and ideally what I'd like is for my operating system
(Windows or Linux) to recognize that every time I type, say, -'C' '1',
a Python script I wrote will execute and out will pop the current date time
in my des
This looks like a job for List Comprehensions!
>>> list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> new_list = [item[1] for item in list]
>>> new_list
[2, 5, 8]
>>>
looks good?
Ian
On 8/21/07, Orest Kozyar <[EMAIL PROTECTED]> wrote:
>
> I've got a "2D" list (essentially a list of lists where all su
I've got a "2D" list (essentially a list of lists where all sublists are of
the same length). The sublists are polymorphic. One "2D" list I commonly
work with is:
[ [datetime object, float, int, float],
[datetime object, float, int, float],
[datetime object, float, int, float] ]
I'd like to
wormwood_3 wrote:
> I ran a few tests, with the following results:
>
> 1. Timing using the time module:
>* Using for loop, src code:
> import time
> start = time.time()
> for word in self.dictcontents:
> se
I ran a few tests, with the following results:
1. Timing using the time module:
* Using for loop, src code:
import time
start = time.time()
for word in self.dictcontents:
self.potdomains.append(word + suffix
Kent Johnson wrote:
> Dave Kuhlman wrote:
>> Consider the following:
>>
>> >>> array = [1,2,3,4,5]
>> >>> array2 = array
>> >>> array = [i * 2 for i in array]
>> >>> array
>> [2, 4, 6, 8, 10]
>> >>> array2
>> [1, 2, 3, 4, 5]
>>
>> So, did you want array2 to change, or no
Dave Kuhlman wrote:
> Consider the following:
>
> >>> array = [1,2,3,4,5]
> >>> array2 = array
> >>> array = [i * 2 for i in array]
> >>> array
> [2, 4, 6, 8, 10]
> >>> array2
> [1, 2, 3, 4, 5]
>
> So, did you want array2 to change, or not?
>
> Here is a solution that
On Mon, Aug 20, 2007 at 03:14:24PM -0300, Ricardo Ar?oz wrote:
[snip]
> > You just work on a generated modified list.
> >
> > foo = range(1,6)
> > for i in [x*2 for x in foo]:
> >do_whatever_you_want_with(i)
> >
>
> What about :
>
> array = [1,2,3,4,5]
> array = [i * 2 for i in array]
>
Kirk Bailey wrote:
> ok, I installed XLRD and can load a xls file; it works quite well BTW. Now
> it is returning Unicode objects. I need to strip that to a simple string
> value. Is there a recommended way or module for handling Unicode objects?
What kind of characters are in the Excel file? Wh
Noufal Ibrahim wrote:
> János Juhász wrote:
>> Dear Tutors!
>>
>> I know a python list is a mutable object.
> array = [1,2,3,4,5]
>> So I can modify any item in it.
> for index in range(len(array)): array[index] *= 2
>> ...
> array
>> [2, 4, 6, 8, 10]
>>
>> So I typed this:
> for i
Thank you Alan and Roel for the insight, and Roel thank you for all the
suggested ways to get around it. It's always nice when something goes from
making no sense to making complete sense in a snap.
Che
_
Booking a flight? Know wh
ok, I installed XLRD and can load a xls file; it works quite well BTW. Now
it is returning Unicode objects. I need to strip that to a simple string
value. Is there a recommended way or module for handling Unicode objects?
Kirk Bailey wrote:
> Ii want to read a xls file and use the data in part
It also seems fair to do the following (if the modified list is to be used
more than once - to avoid building the modified list more than once)?
array = [item*2 for item in array] # instead of for item in array: item
*= 2
Regards,
Trilok
-Original Message-
From: [EMAIL PROTECTED] [
János Juhász wrote:
> Dear Tutors!
>
> I know a python list is a mutable object.
array = [1,2,3,4,5]
>
> So I can modify any item in it.
for index in range(len(array)): array[index] *= 2
> ...
array
> [2, 4, 6, 8, 10]
>
> So I typed this:
for item in array: item *= 2
> ...
Tim Michelsen wrote:
> How nice that the SWC gets updated and improved!
I heard from Chris Lasher at the SWC Sprint on Saturday. Turns out there
is a bug collector for SWC and this bug has been documented for some time:
http://projects.scipy.org/swc/ticket/88
Chris reported, "Will have this fi
>I think what you have is pretty clear. I can't think of a way to do this
>with a single list comprehension because you add two items to the list
>each time through the loop. You could use a list comp and a generator
>expression, but the order of entries in the result will be different:
>self.po
wormwood_3 wrote:
> Hello tutors,
>
> I am trying to understand the best cases in which to use for loops,
list comprehensions, generators, and iterators. I have a rather simple
process that I made initially as a for loop:
>
> self.potdomains = []
> for word in self.dictcontents:
>
Hello tutors,
I am trying to understand the best cases in which to use for loops, list
comprehensions, generators, and iterators. I have a rather simple process that
I made initially as a for loop:
self.potdomains = []
for word in self.dictcontents:
self.potdomains.a
Che M schreef:
> Hi, I am trying to simply create an SQLite database with Python. I find
> that when I try to create a new database file, *sometimes* it lets me do it,
> and sometimes it doesn't, and the only thing I am changing is the name of
> the database. I am baffled as to why some names
"Che M" <[EMAIL PROTECTED]> wrote
> don't. For example, this will create a brand new database on the
> desktop:
>
> conn = sqlite3.connect('C:\Documents and
> Settings\user\Desktop\mydatabase.db')
>
> But running *this*--only thing different is the database's
> name--gives the
> error, as show
"János Juhász" <[EMAIL PROTECTED]> wrote
> So I can modify any item in it.
> >>> for index in range(len(array)): array[index] *= 2
> ...
> >>> array
> [2, 4, 6, 8, 10]
>
> So I typed this:
> >>> for item in array: item *= 2
This is equivalent to
index = 0
while index < len(array):
item = a
Dear Tutors!
I know a python list is a mutable object.
>>> array = [1,2,3,4,5]
So I can modify any item in it.
>>> for index in range(len(array)): array[index] *= 2
...
>>> array
[2, 4, 6, 8, 10]
So I typed this:
>>> for item in array: item *= 2
...
>>> array
[1, 2, 3, 4, 5]
It confused me a
Hi, I am trying to simply create an SQLite database with Python. I find
that when I try to create a new database file, *sometimes* it lets me do it,
and sometimes it doesn't, and the only thing I am changing is the name of
the database. I am baffled as to why some names appear to work and som
23 matches
Mail list logo