Speaking of which, is there some place you or anyone can recommend on
picking up all the constructs for list comprehension & generator
comprehension. I've perused the python.org documents and have just been
building them according to example.
How can I pick up more advanced usage?
I mostly catch
Just a minor related/tangential suggestion -- O'Reilly had a stand at the
recent EuroPython conference I attended and I was paging through
"Bioinformatics Programming using Python", Book reference:
http://oreilly.com/catalog/9780596154516
Just thought I'd mention it as it seems relevant to the cur
"Vikram K" wrote
Suppose i have this string:
z = 'AT/CG'
How do i get this list:
zlist = ['A','T/C','G']
There are lots of ways and it really needs a tighter specification of
yhow you split.
What would "AT/C/DGH" give for example?
But in general there are several approaches, I suspect r
On Thu, 5 Aug 2010 03:40:55 -0400
Sander Sweers wrote:
> On 5 August 2010 06:38, Vikram K wrote:
> > Suppose i have this string:
> > z = 'AT/CG'
> >
> > How do i get this list:
> >
> > zlist = ['A','T/C','G']
>
> If you know the format of the string is always the same you can do
> something lik
On 5 August 2010 06:38, Vikram K wrote:
> Suppose i have this string:
> z = 'AT/CG'
>
> How do i get this list:
>
> zlist = ['A','T/C','G']
If you know the format of the string is always the same you can do
something like this. This fails when you have strings that do not have
the '/' in the midd
On Thu, Aug 5, 2010 at 2:38 PM, Vikram K wrote:
> Suppose i have this string:
> z = 'AT/CG'
>
> How do i get this list:
>
> zlist = ['A','T/C','G']
>>> import re
>>> z = 'AT/CG'
>>> [x for x in re.split("([A-Z]\/[A-Z])|([A-Z])", z) if x]
['A', 'T/C', 'G']
>>>
cheers
James
--
-- James Mills
--
Suppose i have this string:
z = 'AT/CG'
How do i get this list:
zlist = ['A','T/C','G']
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On Thu, Feb 11, 2010 at 8:37 AM, Stefan Behnel wrote:
> Kent Johnson, 11.02.2010 14:16:
>> On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel wrote:
>>
>>> 2) given that you have lists as items in the 'data' list, it's enough to
>>> call sort() once, as the comparison of lists is defined as the compar
Kent Johnson, 11.02.2010 14:16:
> On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel wrote:
>
>> 2) given that you have lists as items in the 'data' list, it's enough to
>> call sort() once, as the comparison of lists is defined as the comparison
>> of each item to the corresponding item of the other
On Thu, Feb 11, 2010 at 4:44 AM, Stefan Behnel wrote:
> 2) given that you have lists as items in the 'data' list, it's enough to
> call sort() once, as the comparison of lists is defined as the comparison
> of each item to the corresponding item of the other list. If you want to
> sort based on t
Owain Clarke, 10.02.2010 17:57:
> data.sort(key=lambda x:x[0])
> data.sort(key=lambda x:x[1])
Two things to note:
1) you can use the operator module, specifically operator.itemgetter
2) given that you have lists as items in the 'data' list, it's enough to
call sort() once, as the comparison of l
On Mi, 2010-02-10 at 16:57 +, Owain Clarke wrote:
> I would love a really clear explanation of lambda!
Generally, lambdas are anonymous functions.
In Python specifically, however, they are limited to simple expressions
(i.e. only what you can put on the right-hand side of an assignment).
my
"Owain Clarke" wrote
I would love a really clear explanation of lambda!
lambda returns an anonymous function - a function without a name.
When we define a function normally we use something like:
def square(x):
return x*x
That creates a function that has the name square
We can do the
With thanks to all who made suggestions, this was what I settled on
f = open('testfile')
#(testfile consisting of 2 columns of data, as per Kent's suggestion)
data = []
for line in f:
line_data = [int(x) for x in line.split()]
data.append(line_data)
data.sort(key=lambda x:x[0])
print "sort by f
If you mean the external shell (say, "bash" under Linux or the DOS
command line in Windows, or similar) then you can only input strings --
everything is a string in such shells.
Yes, I meant capturing data from bash
There are two ways to conv
Owain Clarke, 10.02.2010 14:32:
>> You may want to add a little bit about your use case. Is that really
>> the input you
>> have to deal with? Where does it come from? Can you control the
>> format? What do
>> you want to do with the list you extract from the string?
>>
>> All of that may have an i
On Wednesday February 10 2010 14:32:52 Owain Clarke wrote:
> My son was doing a statistics project in which he had to sort some data by
> either one of two sets of numbers, representing armspan and height of a
> group of children - a boring and painstaking job. I came across this
> piece of cod
On Wed, Feb 10, 2010 at 8:32 AM, Owain Clarke wrote:
> My son was doing a statistics project in which he had to sort some data by
> either one of two sets of numbers, representing armspan and height of a
> group of children - a boring and painstaking job. I came across this piece
> of code:-
>
>
On Thu, 11 Feb 2010 12:32:52 am Owain Clarke wrote:
> My son was doing a statistics project in which he had to sort some
> data by either one of two sets of numbers, representing armspan and
> height of a group of children - a boring and painstaking job. I came
> across this piece of code:-
>
> l
Owain Clarke wrote:
Please excuse the obviousness of my question (if it is), but I have
searched the documentation for how to generate a list e.g. [(1,2),
(3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
me in the right direction.
Many thanks
Owain Clarke
Th
On Wed, Feb 10, 2010 at 6:26 AM, Owain Clarke wrote:
> Please excuse the obviousness of my question (if it is), but I have searched
> the documentation for how to generate a list e.g. [(1,2), (3,4)] from a
> string "[(1,2), (3,4)]". I wonder if someone could point me in the right
> direction.
Pyt
Owain Clarke, 10.02.2010 13:34:
> I have solved it myself - must search more before posting!
>
> If anyone at my kind of level is interested:-
>
mystring = "[(1,2), (3,4)]"
mylist = eval(mystring)
mylist
> [(1,2), (3,4)]
type(mylist)
>
As others have pointed out, this may or
I have solved it myself - must search more before posting!
If anyone at my kind of level is interested:-
>>> mystring = "[(1,2), (3,4)]"
>>> mylist = eval(mystring)
>>> mylist
[(1,2), (3,4)]
>>> type(mylist)
Thanks
Owain Clarke wrote:
Please excuse the obviousness of my question (if it is), b
Owain Clarke, 10.02.2010 12:26:
> Please excuse the obviousness of my question (if it is), but I have
> searched the documentation for how to generate a list e.g. [(1,2),
> (3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
> me in the right direction.
You may want to add a lit
On Wednesday 10 February 2010 11:26:25 am Owain Clarke wrote:
> Please excuse the obviousness of my question (if it is), but I have
> searched the documentation for how to generate a list e.g. [(1,2),
> (3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
> me in the right directi
Owain Clarke wrote:
Please excuse the obviousness of my question (if it is), but I have
searched the documentation for how to generate a list e.g. [(1,2),
(3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
me in the right direction.
Many thanks
Owain Clarke
_
On Wed, 10 Feb 2010 11:26:25 +
Owain Clarke wrote:
> Please excuse the obviousness of my question (if it is), but I have
> searched the documentation for how to generate a list e.g. [(1,2),
> (3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
> me in the right direction
Please excuse the obviousness of my question (if it is), but I have
searched the documentation for how to generate a list e.g. [(1,2),
(3,4)] from a string "[(1,2), (3,4)]". I wonder if someone could point
me in the right direction.
Many thanks
Owain Clarke
__
> name like "foo" to be changed
Nitpick: "foo" is a string, not a name...
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Or, you could do:
In [1]: print list(raw_input('name please...'))
name please...John
['J', 'o', 'h', 'n']
Robert Berman
Kent Johnson wrote:
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman
wrote:
Hello,
I am a beginner. And I am trying to get a user input converted to a lis
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman
wrote:
> Hello,
>
> I am a beginner. And I am trying to get a user input converted to a list.
>
> print 'Enter your first name :'
> firstname = raw_input()
>
> So if the user input is
>
> firstname = 'foo' --->should become>
> fir
On Tue, Feb 24, 2009 at 10:16 AM, Taylan Karaman wrote:
> Hello,
>
> I am a beginner. And I am trying to get a user input converted to a list.
>
> print 'Enter your first name :'
> firstname = raw_input()
>
> So if the user input is
>
> firstname = 'foo'--->should become>
> fir
Hello,
I am a beginner. And I am trying to get a user input converted to a list.
print 'Enter your first name :'
firstname = raw_input()
So if the user input is
firstname = 'foo'--->should become>
firstlist['f','o','o']
thanks in advance
___
Just the thing Light and Chuck - I thought there might be something
simple (and I've used the join method before duh).
Thanks,
Lee C
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
Hello Chinook,
How about join(), as in
''.join(strlist)
?
Saturday, July 2, 2005, 9:45:28 PM, you wrote:
C> I'm missing something simple again. The simplified issue is:
C> Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
C> >>> mystr = 'abc'
C> # I can create a list of the string characters
C>
Hi, Lee.
You could using:
>>> bts = ''.join(strlist)
Then you would get:
>>> bts'abc'
Light
FOX.GIF
Description: GIF image
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
I'm missing something simple again. The simplified issue is:
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
>>> mystr = 'abc'
# I can create a list of the string characters
# with list comprehension
>>> [c for c in mystr]
['a', 'b', 'c']
# Or just a simple builtin conversion function
>>> l
37 matches
Mail list logo