Re: on generating combinations among a variable list of lists

2020-06-28 Thread Boris Dorestand
(1, 2, 10) > (1, 3, 1) > (1, 3, 10) > (3, 2, 1) > (3, 2, 10) > (3, 3, 1) > (3, 3, 10) > (5, 2, 1) > (5, 2, 10) > (5, 3, 1) > (5, 3, 10) > (7, 2, 1) > (7, 2, 10) > (7, 3, 1) > (7, 3, 10) That's precisely it. I missed product. Thanks! > If you n

Re: on generating combinations among a variable list of lists

2020-06-28 Thread Peter Otten
u need lists instead of tuples convert them >>> list(t) [7, 3, 10] To pass a varying number of lists use a list of lists and a star argument: >>> lists = [[[1, 2], [3, 4]], [[10, 20, 30], [40, 50]]] >>> for item in lists: ... print(list(itertools.product(*item))) ...

on generating combinations among a variable list of lists

2020-06-28 Thread Boris Dorestand
Say we have [1,3,5,7], [2,3], [1,10]. I'd like to generate [1,2,1] [1,2,10] [1,3,1] [1,3,10] [3,2,1] [3,2,10] [3,3,1] [3,3,10] [5, ...] ... [7,3,10] The number of input lists is variable. The example shows three lists, but there could be only one or ten lists or any

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Jaap Woldringh
Jaap Woldringh added the comment: Op 17-01-2020 om 14:03 schreef Karthikeyan Singaravelan: > Karthikeyan Singaravelan added the comment: > > You're referencing to the same list 3 times in B. So modifying it once means > all the elements referring to same object reflect the change. Make a copy

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Ezio Melotti
Ezio Melotti added the comment: See also https://docs.python.org/3/faq/programming.html#why-did-changing-list-y-also-change-list-x You can use the builtin function id() to see the id of the lists, and verify whether they refer to the same object or not. -- nosy: +ezio.melotti

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: You're referencing to the same list 3 times in B. So modifying it once means all the elements referring to same object reflect the change. Make a copy of the list during append to ensure modification of one doesn't affect other. This is not a

[issue39368] A matrix (list of lists) behaves differently, depending how it is created

2020-01-17 Thread Jaap Woldringh
t.py messages: 360182 nosy: jjhwoldringh priority: normal severity: normal status: open title: A matrix (list of lists) behaves differently, depending how it is created type: behavior versions: Python 3.6 Added file: https://bugs.python.org/file48849/matrix_experiment.py __

Re: list of lists

2018-07-23 Thread Sharan Basappa
On Sunday, 22 July 2018 21:07:17 UTC+5:30, Thomas Jollans wrote: > On 22/07/18 14:53, Sharan Basappa wrote: > > Thanks. I initially thought about this but did not know if this is legal > > syntax. > > In this kind of situation – you think you know how to do something but > you're not quite sure

Re: list of lists

2018-07-22 Thread Thomas Jollans
On 22/07/18 14:53, Sharan Basappa wrote: > Thanks. I initially thought about this but did not know if this is legal > syntax. In this kind of situation – you think you know how to do something but you're not quite sure if it'll work as intended – just try it! Start up an interactive interpreter,

Re: list of lists

2018-07-22 Thread Sharan Basappa
aran Basappa wrote: > > > ​​ > > > > Thanks. This works in my example. Can you tell me how this works? > > > > > You can simply unpack the inner list: > > > > > > a, b = results[0] > > > > > > > > > Iwo Herk

Re: list of lists

2018-07-22 Thread Iwo Herka
erka > > > > ‐‐‐ Original Message ‐‐‐ > > > > On 22 July 2018 11:47 AM, Sharan Basappa sharan.basa...@gmail.com wrote: > > > > > I am using a third party module that is returning list of lists. > > > > > > I am using the example b

Re: list of lists

2018-07-22 Thread Sharan Basappa
On Sunday, 22 July 2018 18:15:23 UTC+5:30, Frank Millman wrote: > "Sharan Basappa" wrote in message > news:8e261f75-03f7-4f80-a516-8318dd138...@googlegroups.com... > > > > I am using a third party module that is returning list of lists. > > I am using the exam

Re: list of lists

2018-07-22 Thread Frank Millman
"Sharan Basappa" wrote in message news:8e261f75-03f7-4f80-a516-8318dd138...@googlegroups.com... I am using a third party module that is returning list of lists. I am using the example below to illustrate. 1 results = [['1', 0.99921393753233001]] 2 k = results[0] 3 print k[0] 4

Re: list of lists

2018-07-22 Thread Sharan Basappa
gt; > > > I am using a third party module that is returning list of lists. > > > > I am using the example below to illustrate. > > > > 1 results = [['1', 0.99921393753233001]] > > > > 2 k = results[0] > > > > 3 print k[0] > > > &g

Re: list of lists

2018-07-22 Thread Iwo Herka
You can simply unpack the inner list: a, b = results[0] Iwo Herka ‐‐‐ Original Message ‐‐‐ On 22 July 2018 11:47 AM, Sharan Basappa wrote: > ​​ > > I am using a third party module that is returning list of lists. > > I am using the example below to illustrate.

list of lists

2018-07-22 Thread Sharan Basappa
I am using a third party module that is returning list of lists. I am using the example below to illustrate. 1 results = [['1', 0.99921393753233001]] 2 k = results[0] 3 print k[0] 4 print k[1] Assume the line 1 is what is returned. I am assigning that to another list (k on line 2

Re: Problem of writing long list of lists file to csv

2018-05-22 Thread subhabangalore
On Tuesday, May 22, 2018 at 3:55:58 PM UTC+5:30, Peter Otten wrote: > > > > lst2=lst1[:4] > > with open("my_csv.csv","wb") as f: > > writer = csv.writer(f) > > writer.writerows(lst2) > > > > Here it is writing only the first four lists. > > Hint: look at the first line

Re: Problem of writing long list of lists file to csv

2018-05-22 Thread Peter Otten
subhabangal...@gmail.com wrote: > lst2=lst1[:4] > with open("my_csv.csv","wb") as f: > writer = csv.writer(f) > writer.writerows(lst2) > > Here it is writing only the first four lists. Hint: look at the first line in the quotation above. --

Problem of writing long list of lists file to csv

2018-05-22 Thread subhabangalore
I have a list of lists (177 lists). I am trying to write them as file. I used the following code to write it in a .csv file. import csv def word2vec_preprocessing(): a1=open("/python27/EngText1.txt","r") list1=[] for line in a1: line1=line.lower().r

[issue32508] Problem while reading back from a list of lists

2018-01-07 Thread J Viswanathan
Steven D'Aprano <rep...@bugs.python.org> wrote: > > Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: > > It isn't clear to me what bug you are reporting here: > > - What do you mean by "problem reading back from a list of lists"? What

[issue32508] Problem while reading back from a list of lists

2018-01-06 Thread Steven D'Aprano
Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: It isn't clear to me what bug you are reporting here: - What do you mean by "problem reading back from a list of lists"? What sort of problem? - What makes you think that there is a bug in the interpreter, rath

[issue32508] Problem while reading back from a list of lists

2018-01-06 Thread J Viswanathan
Jan 7 07:54:52 = The correct results are: x: 0klist: [1,2,4] x: 1klist [2,4,7] x:2 klist: [2,4,7] etc. -- files: check_su.dat, compilation_log, hksu_copy.py messages: 309597 nosy: JHari priority: normal severity: normal status: open title: Problem while reading

Re: How to flatten only one sub list of list of lists

2017-04-01 Thread Robert L.
On 3/1/2017, Sayth Renshaw wrote: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83

Re: How to flatten only one sub list of list of lists

2017-03-01 Thread Sayth Renshaw
> Replace the slice row[index:index+1] with row[index], either by building a > new list or in place: > > >>> def show(data): > ...for item in data: print(item) > ... > >>> def flatten_one(rows, index): > ... return [r[:index] + r[index] + r[index+1:] for r in rows] > ... > >>> def

Re: How to flatten only one sub list of list of lists

2017-02-28 Thread Peter Otten
Sayth Renshaw wrote: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 > [ [$277790.00']], > ['46295', 'Dark Eyes', '5', '59',

Re: How to flatten only one sub list of list of lists

2017-02-28 Thread Jussi Piitulainen
Sayth Renshaw writes: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4

How to flatten only one sub list of list of lists

2017-02-28 Thread Sayth Renshaw
How can I flatten just a specific sublist of each list in a list of lists? So if I had this data [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], ['46295', 'Machinegun Jubs', '6', '53

Re: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Michael Torrie
On 01/12/2017 02:26 AM, Deborah Swanson wrote: > It's true, I've only been on this list a few weeks, although I've seen > and been on the receiving end of the kind of "help" that feels more like > being sneered at than help. Not on this list, but on Linux and similar > lists. There does seem to be

Re: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Chris Angelico
On Thu, Jan 12, 2017 at 9:27 PM, Marko Rauhamaa wrote: > An instructive anecdote: somebody I know told me he once needed the > definitive list of some websites. He posted a question on the relevant > online forum, but it fell on deaf ears. After some days, he replied to > his

Re: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Marko Rauhamaa
"Deborah Swanson" : > I've only been on this list a few weeks, although I've seen and been > on the receiving end of the kind of "help" that feels more like being > sneered at than help. Not on this list, but on Linux and similar > lists. There does seem to be a "tough

RE: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Deborah Swanson
Antoon Pardon wrote, on January 12, 2017 12:49 AM > > Op 11-01-17 om 23:57 schreef Deborah Swanson: > > > >> What are we supposed to do when somebody asks a question based on an > >> obvious mistake? Assume that they're a quick learner who has probably > >> already worked out their mistake and

Re: Using namedtuples field names for column indices in a list of lists

2017-01-12 Thread Antoon Pardon
Op 11-01-17 om 23:57 schreef Deborah Swanson: > >> What are we supposed to do when somebody asks a question based on an >> obvious mistake? Assume that they're a quick learner who has probably >> already worked out their mistake and doesn't need an answer? That >> would certainly make our life

RE: Using namedtuples field names for column indices in a list of lists

2017-01-11 Thread Deborah Swanson
Steven D'Aprano wrote, on January 10, 2017 6:19 PM > > On Tuesday 10 January 2017 18:14, Deborah Swanson wrote: > > > I'm guessing that you (and those who see things like you do) might > > not be used to working with quick learners who make mistakes at > > first but catch up with them real

Re: Using namedtuples field names for column indices in a list of lists

2017-01-11 Thread BartC
On 11/01/2017 02:18, Steven D'Aprano wrote: On Tuesday 10 January 2017 18:14, Deborah Swanson wrote: I'm guessing that you (and those who see things like you do) might not be used to working with quick learners who make mistakes at first but catch up with them real fast, or you're very

RE: Using namedtuples field names for column indices in a list of lists

2017-01-10 Thread Steven D'Aprano
On Tuesday 10 January 2017 18:14, Deborah Swanson wrote: > I'm guessing that you (and those who > see things like you do) might not be used to working with quick learners > who make mistakes at first but catch up with them real fast, or you're > very judgemental about people who make mistakes,

Re: Using namedtuples field names for column indices in a list of lists

2017-01-10 Thread Ethan Furman
On 01/09/2017 11:14 PM, Deborah Swanson wrote: So I guess you should just do your thing and I'll do mine. As you say. Takes all kinds, and I think in the end what will count is the quality of my finished work (which has always been excellent), and not the messy process to get there.

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
ght here. > > Indeed. > > The issue I (and others) see, though, is more along the lines > of basic understanding: you seemed to think that a list of > lists should act the same as a list of tuples, even though > lists and tuples are not the same thing. It's like expecting &g

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Ethan Furman
t is right here. Indeed. The issue I (and others) see, though, is more along the lines of basic understanding: you seemed to think that a list of lists should act the same as a list of tuples, even though lists and tuples are not the same thing. It's like expecting a basket of oranges to b

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
s > ... > >>> type(foo()) > > >>> > > ... type() will tell you what class your object is an instance of. > "" tells you that your object is a list. > > > And it behaves like a list sometimes, but many times > > not. > > I thin

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
4.0 (default, Apr 11 2014, 13:05:18) > ... > --> type(list) > > --> > --> type(list()) > > --> type([1, 2, 3]) > > > So the `list` type is 'type', and the type of list instances > is 'class list'. I just saw that while replying to MRAB. 'records

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
never looked at the type of a list before, probably because lists are so obvious by looking at them. > > 'records' is in fact a class, it has an fget method and data members > > that I've used. And it behaves like a list sometimes, but many times not. > > > Its type

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Erik
On 10/01/17 03:02, Deborah Swanson wrote: Erik wrote, on January 09, 2017 5:47 PM IIRC, you create it using a list comprehension which creates the records. A list comprehension always creates a list. Well no. The list is created with: records.extend(Record._make(row) for row in rows) No,

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Ethan Furman
On 01/09/2017 07:02 PM, Deborah Swanson wrote: Erik wrote, on January 09, 2017 5:47 PM As people keep saying, the object you have called 'records' is a *list* of namedtuple objects. It is not a namedtuple. IIRC, you create it using a list comprehension which creates the records. A list

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread MRAB
On 2017-01-10 03:02, Deborah Swanson wrote: Erik wrote, on January 09, 2017 5:47 PM As people keep saying, the object you have called 'records' is a *list* of namedtuple objects. It is not a namedtuple. IIRC, you create it using a list comprehension which creates the records. A list

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Erik wrote, on January 09, 2017 5:47 PM > As people keep saying, the object you have called 'records' > is a *list* > of namedtuple objects. It is not a namedtuple. > > IIRC, you create it using a list comprehension which creates the > records. A list comprehension always creates a list. Well

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Erik
On 10/01/17 00:54, Deborah Swanson wrote: Since I won't change the order of the records again after the sort, I'm using records.sort(key=operator.attrgetter("Description", "Date")) once, which also works perfectly. So both sorted() and sort() can be used to sort namedtuples. Good to know!

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Peter Otten wrote, on January 09, 2017 3:27 PM > > While stable sort is nice in this case you can just say > > key=operator.attrgetter("Description", "Date") > > Personally I'd only use sorted() once and then switch to the > sort() method. This works perfectly, thank you. As I read the docs,

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
breamore...@gmail.com wrote: > On Monday, January 9, 2017 at 5:34:12 PM UTC, Tim Chase wrote: >> On 2017-01-09 08:31, breamoreboy wrote: >> > On Monday, January 9, 2017 at 2:22:19 PM UTC, Tim Chase wrote: >> > > I usually wrap the iterable in something like >> > > >> > > def pairwise(it): >> >

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread breamoreboy
On Monday, January 9, 2017 at 5:34:12 PM UTC, Tim Chase wrote: > On 2017-01-09 08:31, breamoreboy wrote: > > On Monday, January 9, 2017 at 2:22:19 PM UTC, Tim Chase wrote: > > > I usually wrap the iterable in something like > > > > > > def pairwise(it): > > > prev = next(it) > > > for

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
Rhodri James wrote: > On 09/01/17 21:40, Deborah Swanson wrote: >> Peter Otten wrote, on January 09, 2017 6:51 AM >>> >>> records = sorted( >>> set(records), >>> key=operator.attrgetter("Description") >>> ) >> >> Good, this is confirmation that 'sorted()' is the way to go. I want a 2 >>

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Rhodri James
On 09/01/17 21:40, Deborah Swanson wrote: Peter Otten wrote, on January 09, 2017 6:51 AM records = sorted( set(records), key=operator.attrgetter("Description") ) Good, this is confirmation that 'sorted()' is the way to go. I want a 2 key sort, Description and Date, but I think I can

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
breamore...@gmail.com wrote, on January 09, 2017 8:32 AM > > On Monday, January 9, 2017 at 2:22:19 PM UTC, Tim Chase wrote: > > On 2017-01-08 22:58, Deborah Swanson wrote: > > > 1) I have a section that loops through the sorted data, compares two > > > adjacent rows at a time, and marks one of

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Tim Chase wrote, on January 09, 2017 6:22 AM > > On 2017-01-08 22:58, Deborah Swanson wrote: > > 1) I have a section that loops through the sorted data, compares two > > adjacent rows at a time, and marks one of them for deletion if the > > rows are identical. > > and my question is whether

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Peter Otten wrote, on January 09, 2017 6:51 AM > > Deborah Swanson wrote: > > > Even better, to get hold of all the records with the same Description > > as the current row, compare them all, mark all but the different ones > > for deletion, and then resume processing the records after the

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread breamoreboy
On Monday, January 9, 2017 at 2:22:19 PM UTC, Tim Chase wrote: > On 2017-01-08 22:58, Deborah Swanson wrote: > > 1) I have a section that loops through the sorted data, compares two > > adjacent rows at a time, and marks one of them for deletion if the > > rows are identical. > > > > I'm using >

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Peter Otten
Deborah Swanson wrote: > Even better, to get hold of all the records with the same Description as > the current row, compare them all, mark all but the different ones for > deletion, and then resume processing the records after the last one? When you look at all fields for deduplication anyway

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Tim Chase
On 2017-01-08 22:58, Deborah Swanson wrote: > 1) I have a section that loops through the sorted data, compares two > adjacent rows at a time, and marks one of them for deletion if the > rows are identical. > > I'm using > > for i in range(len(records)-1): > r1 = records[i] > r2 =

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Steve D'Aprano wrote, on January 09, 2017 3:40 AM > > On Mon, 9 Jan 2017 09:57 pm, Deborah Swanson wrote: > > [...] > > I think you are replying to my question about sorting a > namedtuple, in > > this case it's called 'records'. > > > > I think your suggestion works for lists and tuples, and

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Steve D'Aprano
On Mon, 9 Jan 2017 09:57 pm, Deborah Swanson wrote: [...] > I think you are replying to my question about sorting a namedtuple, in > this case it's called 'records'. > > I think your suggestion works for lists and tuples, and probably > dictionaries. But namedtuples doesn't have a sort function.

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Antoon Pardon wrote, on January 09, 2017 2:35 AM > If I understand correctly you want something like: > > records.sort(key = lamda rec: rec.xx) > > AKA > > from operator import attrgetter > records.sort(key = attrgetter('xx')) > > or maybe: > > records.sort(key = lambda rec:

RE: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Deborah Swanson
Antoon Pardon wrote, on January 09, 2017 2:14 AM > > 1) I have a section that loops through the sorted data, compares two > > adjacent rows at a time, and marks one of them for deletion if the > > rows are identical. > > > > I'm using > > > > for i in range(len(records)-1): > > r1 =

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Antoon Pardon
Op 09-01-17 om 07:58 schreef Deborah Swanson: > Peter Otten wrote, on January 08, 2017 5:21 AM >> Deborah Swanson wrote: >> >>> Peter Otten wrote, on January 08, 2017 3:01 AM >> >> Personally I would recommend against mixing data (an actual location) > and >> metadata (the column

Re: Using namedtuples field names for column indices in a list of lists

2017-01-09 Thread Antoon Pardon
Op 09-01-17 om 07:58 schreef Deborah Swanson: > Peter Otten wrote, on January 08, 2017 5:21 AM >> Deborah Swanson wrote: >> >>> Peter Otten wrote, on January 08, 2017 3:01 AM >> >> Personally I would recommend against mixing data (an actual location) > and >> metadata (the column

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Steven D'Aprano wrote, on January 08, 2017 7:30 PM > > On Sunday 08 January 2017 20:53, Deborah Swanson wrote: > > > Steven D'Aprano wrote, on January 07, 2017 10:43 PM > > No, I'm pretty sure that's not the case. I don't have access > to your CSV file, > but I can simulate it: > > ls =

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Peter Otten wrote, on January 08, 2017 5:21 AM > > Deborah Swanson wrote: > > > Peter Otten wrote, on January 08, 2017 3:01 AM > > Personally I would recommend against mixing data (an actual location) and > metadata (the column name,"Location"), but if you wish my code can be > adapted as

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Steven D'Aprano wrote, on January 07, 2017 10:43 PM > > On Sunday 08 January 2017 16:39, Deborah Swanson wrote: > > The recommended way is with the _replace method: > > py> instance._replace(A=999) > Record(A=999, B=20, C=30) > py> instance._replace(A=999, C=888) > Record(A=999, B=20, C=888) >

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Steven D'Aprano
On Sunday 08 January 2017 20:53, Deborah Swanson wrote: > Steven D'Aprano wrote, on January 07, 2017 10:43 PM >> >> On Sunday 08 January 2017 16:39, Deborah Swanson wrote: >> >> > What I've done so far: >> > >> > with open('E:\\Coding projects\\Pycharm\\Moving\\Moving >> 2017 in.csv', >> >

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Paul Rudin wrote, on January 08, 2017 6:49 AM > > "Deborah Swanson" writes: > > > Peter Otten wrote, on January 08, 2017 3:01 AM > >> > >> columnA = [record.A for record in records] > > > > This is very neat. Something like a list comprehension for named > > tuples?

Re: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Paul Rudin
"Deborah Swanson" writes: > Peter Otten wrote, on January 08, 2017 3:01 AM >> >> columnA = [record.A for record in records] > > This is very neat. Something like a list comprehension for named tuples? Not something like - this *is* a list comprehension - it creates a

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Peter Otten wrote, on January 08, 2017 5:21 AM > > Deborah Swanson wrote: > > > Peter Otten wrote, on January 08, 2017 3:01 AM > >> > >> Deborah Swanson wrote: > >> > >> > to do that is with .fget(). Believe me, I tried every > possible > >> > way > > to > >> > use instance.A or instance[1]

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
Deborah Swanson wrote: > Peter Otten wrote, on January 08, 2017 3:01 AM >> >> Deborah Swanson wrote: >> >> > to do that is with .fget(). Believe me, I tried every > possible way > to >> > use instance.A or instance[1] and no way could I get ls[instance.A]. >> >> Sorry, no. > > I quite agree,

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Peter Otten wrote, on January 08, 2017 3:01 AM > > Deborah Swanson wrote: > > > to do that is with .fget(). Believe me, I tried every > possible way to > > use instance.A or instance[1] and no way could I get ls[instance.A]. > > Sorry, no. I quite agree, I was describing the dead end I was in

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
Deborah Swanson wrote: > to do that is with .fget(). Believe me, I tried every possible way to > use instance.A or instance[1] and no way could I get ls[instance.A]. Sorry, no. To get a list of namedtuple instances use: rows = csv.reader(infile) Record = namedtuple("Record", next(rows))

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
Steven D'Aprano wrote, on January 07, 2017 10:43 PM > > On Sunday 08 January 2017 16:39, Deborah Swanson wrote: > > > What I've done so far: > > > > with open('E:\\Coding projects\\Pycharm\\Moving\\Moving > 2017 in.csv', > > 'r') as infile: > > ls = list(csv.reader(infile)) > > lst =

Re: Using namedtuples field names for column indices in a list of lists

2017-01-07 Thread Steven D'Aprano
On Sunday 08 January 2017 16:39, Deborah Swanson wrote: > What I've done so far: > > with open('E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in.csv', > 'r') as infile: > ls = list(csv.reader(infile)) > lst = namedtuple('lst', ls[0]) > > where 'ls[0]' is the header row of the csv,

Using namedtuples field names for column indices in a list of lists

2017-01-07 Thread Deborah Swanson
What I've done so far: with open('E:\\Coding projects\\Pycharm\\Moving\\Moving 2017 in.csv', 'r') as infile: ls = list(csv.reader(infile)) lst = namedtuple('lst', ls[0]) where 'ls[0]' is the header row of the csv, and it works perfectly well. 'lst' is a namedtuple instance with each of

Problem in creating list of lists

2016-02-29 Thread subhabangalore
it as, [[('the','DT'),('film', 'NN'),('was','AV'),('nice','ADJ')],[('leonardo','NN'),('is','AV'),('great','ADJ')],[('it','PRP'), ('was','AV'),('academy','NN'),('award','NN')]] that is a list of lists where in each list there is a set of tuples. I could solve each one like I am getting one list

Re: How may I change values in tuples of list of lists?

2016-02-23 Thread Ben Finney
subhabangal...@gmail.com writes: > Now if I want to change the values of tags like 'AT', 'NP-TL', > 'NN-TL', etc. to some arbitrary ones like XX,YY,ZZ and yet preserve > total structure of tuples in list of lists, please suggest how may I > do it. Changing items in lists is done

How may I change values in tuples of list of lists?

2016-02-23 Thread subhabangalore
Hi I am trying to use the following set of tuples in list of lists. I am using a Python based library named, NLTK. >>> import nltk >>> from nltk.corpus import brown as bn >>> bt=bn.tagged_sents() >>> bt_5=bt[:5] >>> print bt [[(u'The', u'AT'

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread HKRSS
gt; list_of_lists[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] > [[...]] > Sorry For Bad Question, But I need List Of Lists That I Can Acces Horyzontaly, Not In The Deep(But This IS Not All, I End That Evey List In List Of Lists Can Be A List... Thanks In Advance... Robert..;) -- https://mail.python.org/mailman/listinfo/python-list

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread robert . bralic
Dana petak, 20. studenoga 2015. u 14:06:31 UTC+1, korisnik Nagy László Zsolt napisao je: > > Sorry For Bad Question, But I need List Of Lists That I Can > > Acces Horyzontaly, Not In The Deep(But This IS Not All, > > I End That Evey List In List Of Lists Can Be A List... &g

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Nagy László Zsolt
> Sorry For Bad Question, But I need List Of Lists That I Can > Acces Horyzontaly, Not In The Deep(But This IS Not All, > I End That Evey List In List Of Lists Can Be A List... It is not possible to do it with a native list. But you can write your own iterable that can be iterate

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Chris Angelico
On Sat, Nov 21, 2015 at 12:06 AM, Nagy László Zsolt <gand...@shopzeus.com> wrote: >> Sorry For Bad Question, But I need List Of Lists That I Can >> Acces Horyzontaly, Not In The Deep(But This IS Not All, >> I End That Evey List In List Of Lists Can Be A List... &g

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Grant Edwards
On 2015-11-20, HKRSS <hk...@gmail.com> wrote: > > Sorry For Bad Question, But I need List Of Lists That I Can > Acces Horyzontaly, Not In The Deep(But This IS Not All, > I End That Evey List In List Of Lists Can Be A List... > > Thanks In Advance... > Robert..;)

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Denis McMahon
On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: > Thanks In Advance, Robert...;) Just keep appending child lists to parent list: l = [] while True: l.append([]) Until you run out of memory But I think that this answer although it appears accurate to the question is not a solut

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread srinivas devaki
On Fri, Nov 20, 2015 at 6:39 PM, Chris Angelico wrote: > My crystal ball suggests that defaultdict(list) might be useful here. > > ChrisA I used something similar to this for some problem in hackerrank, anyway i think this is what you want. class defaultlist(object): def

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread robert . bralic
Dana petak, 20. studenoga 2015. u 18:16:52 UTC+1, korisnik Denis McMahon napisao je: > On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: > > > Thanks In Advance, Robert...;) > > Just keep appending child lists to parent list: > > l = [] > > while True: >l.

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread srinivas devaki
On Fri, Nov 20, 2015 at 11:58 PM, srinivas devaki wrote: > def __str__(self): > if len(self.list) == 0: > return '(' + str(self.data) + ')[...]' > return ''.join(['(', str(self.data), ')['] + map(str, self.list) + > [', ...]']) > ... >

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Ian Kelly
On Fri, Nov 20, 2015 at 11:16 AM, <robert.bra...@si.t-com.hr> wrote: > Dana petak, 20. studenoga 2015. u 18:16:52 UTC+1, korisnik Denis McMahon > napisao je: >> On Fri, 20 Nov 2015 08:43:04 +0100, HKRSS wrote: >> >> > Thanks In Advance, Robert...;) >> >&

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Chris Angelico
On Sat, Nov 21, 2015 at 5:16 AM, wrote: > I Think That LISP Is Only Solution, I Wil Give Up Frpm Python... Capital Letters For The Win. You Should Consider Talking In German. ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread sohcahtoa82
gt; > > > Just keep appending child lists to parent list: > > > > l = [] > > > > while True: > >l.append([]) > > > > Until you run out of memory > > > > But I think that this answer although it appears accurate to the question &

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread Peter Otten
HKRSS wrote: > Thanks In Advance, Robert...;) >>> list_of_lists = [] >>> list_of_lists.append(list_of_lists) >>> list_of_lists[0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0][0] [[...]] -- https://mail.python.org/mailman/listinfo/python-list

How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread HKRSS
Thanks In Advance, Robert...;) -- https://mail.python.org/mailman/listinfo/python-list

Re: How To Create A Endles List Of Lists In Python...???

2015-11-20 Thread HKRSS
I Think That There Are Two Ways: 1)Harder Way Use Procedural C... 2)Easier Way Use LISP... "HKRSS" wrote in message news:n2miu8$fl4$1...@ls237.t-com.hr... > Thanks In Advance, Robert...;) > > -- https://mail.python.org/mailman/listinfo/python-list

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Martin Panter
Martin Panter added the comment: This is how Python is meant to work; see https://docs.python.org/2.7/faq/programming.html#how-do-i-create-a-multidimensional-list. Unless there is something in the documentation that gave you the wrong impression, I suggest we close this. -- nosy:

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Martin Panter
Changes by Martin Panter vadmium...@gmail.com: -- stage: - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24589 ___

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Zorceta
Zorceta added the comment: FYI: ll = [[]]*10 [id(l) for l in ll] [67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296, 67940296] -- nosy: +zorceta ___ Python tracker rep...@bugs.python.org

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Jos Dechamps
New submission from Jos Dechamps: After creating a list of lists, changing one element, leads to changes of all the elements: v=[[]]*10 v [[], [], [], [], [], [], [], [], [], []] v[3].append(3) v [[3], [3], [3], [3], [3], [3], [3], [3], [3], [3]] v=[[]]*10 v

[issue24589] Wrong behavior for list of lists

2015-07-08 Thread Bastiaan Albarda
Bastiaan Albarda added the comment: The * operator lets you use the same object multiple times, thereby saving resources. If you want unique objects use comprehension: v = [[] for x in range(10)] v[3].append(3) v [[], [], [], [3], [], [], [], [], [], []] v[3] += [3] v [[], [], [], [3,

Re: A question on the creation of list of lists

2015-04-28 Thread alex23
On 23/04/2015 2:18 AM, subhabrata.bane...@gmail.com wrote: I have a list of file names of a directory, I want to read each one of them. After reading each one of them, I want to put the results of each file in a list. These lists would again be inserted to create a list of lists. While

  1   2   3   4   5   >