list

All possible combination of pairs + 1 triple group from an odd list?

隐身守侯 提交于 2021-02-10 14:35:34
问题 Starting with an odd list of students, let’s say 21 total: cohort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] I want use Python to write a function that assign pairs for group projects every day with different pairings. Since we have an odd number of students, I don’t want anyone to be working alone, so we would need to have 9 groups of 2 people and 1 group of 3 people . Every day they would change partners. For example, on day 1 and day 2, the groups would

All possible combination of pairs + 1 triple group from an odd list?

随声附和 提交于 2021-02-10 14:35:16
问题 Starting with an odd list of students, let’s say 21 total: cohort = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] I want use Python to write a function that assign pairs for group projects every day with different pairings. Since we have an odd number of students, I don’t want anyone to be working alone, so we would need to have 9 groups of 2 people and 1 group of 3 people . Every day they would change partners. For example, on day 1 and day 2, the groups would

reshape an irregular list in python

扶醉桌前 提交于 2021-02-10 14:29:45
问题 I would like to reshape the following list : wide_list = [[1,['a','b','c']],[2,['d','e']],[3,'f']] in a "long format": long_list = [[1,'a'],[1,'b'],[1,'c'],[2,'d'],[2,'e'],[3,'f']] How can this be achieved efficiently in Python? 回答1: Try a nested list comprehension: >>> wide_list = [[1,['a','b','c']],[2,['d','e']],[3, ['f']]] >>> long_list = [[k, v] for k, sublist in wide_list for v in sublist] >>> long_list [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'd'], [2, 'e'], [3, 'f']] Note, the last group had

question about print List<T> to screen

人走茶凉 提交于 2021-02-10 14:21:05
问题 A question about List; When i have "List<PlugwiseMessage> msg" with the value's from the picture : I only get PlugwiseLib.BLL.BC.PlugwiseMessage as output. But how can i see the value's from _message, _owner and _type on my screen ? or the value's of Message, Owner, and Type ? And can somebody explain the difference to me ? 回答1: Your list has a collection of PlugwiseLib.BLL.BC.PlugwiseMessage objects. Message, Owner and Type are properties on the object. The _message, _owner and _type

question about print List<T> to screen

荒凉一梦 提交于 2021-02-10 14:21:01
问题 A question about List; When i have "List<PlugwiseMessage> msg" with the value's from the picture : I only get PlugwiseLib.BLL.BC.PlugwiseMessage as output. But how can i see the value's from _message, _owner and _type on my screen ? or the value's of Message, Owner, and Type ? And can somebody explain the difference to me ? 回答1: Your list has a collection of PlugwiseLib.BLL.BC.PlugwiseMessage objects. Message, Owner and Type are properties on the object. The _message, _owner and _type

List of dict of dict in Pandas

可紊 提交于 2021-02-10 14:18:19
问题 I have list of dict of dicts in the following form: [{0:{'city':'newyork', 'name':'John', 'age':'30'}}, {0:{'city':'newyork', 'name':'John', 'age':'30'}},] I want to create pandas DataFrame in the following form: city name age newyork John 30 newyork John 30 Tried a lot but without any success can you help me? 回答1: Use list comprehension with concat and DataFrame.from_dict: L = [{0:{'city':'newyork', 'name':'John', 'age':'30'}}, {0:{'city':'newyork', 'name':'John', 'age':'30'}}] df = pd

Update list elements based on a second list as index

做~自己de王妃 提交于 2021-02-10 14:17:52
问题 A not too difficult question, I hope, from a beginner in Python. I have a main list, listA, and I need to zero out items in that list based on values in an index list, listB. So, for example, given: listA = [10, 12, 3, 8, 9, 17, 3, 7, 2, 8] listB = [1, 4, 8, 9] the output I want is listC = [10, 0, 3, 8, 0, 17, 3, 7, 0, 0] This question [1] seems similar, but asked for the elements to be removed, not changed. I'm not sure if a similar approach is needed, but if so I can't see how to apply it.

Update list elements based on a second list as index

家住魔仙堡 提交于 2021-02-10 14:06:56
问题 A not too difficult question, I hope, from a beginner in Python. I have a main list, listA, and I need to zero out items in that list based on values in an index list, listB. So, for example, given: listA = [10, 12, 3, 8, 9, 17, 3, 7, 2, 8] listB = [1, 4, 8, 9] the output I want is listC = [10, 0, 3, 8, 0, 17, 3, 7, 0, 0] This question [1] seems similar, but asked for the elements to be removed, not changed. I'm not sure if a similar approach is needed, but if so I can't see how to apply it.

List comprehension with tuple assignment

て烟熏妆下的殇ゞ 提交于 2021-02-10 13:42:30
问题 I want to ask if something like this is possible in python: a,b = [i,i+1 for i in range(5)] I know this isn't possible because I have got an error, but I think you understand what I am trying to achieve. Let me clear it up, I can do : a,b = 3+2,3 Edit ---> Or even better: a,b = [0,1,2,3,4],[1,2,3,4,5] I wan't a similar thing in my first code example. I am trying to assign variables 'a' and 'b' as list, with list comprehension, but using tuple as assignment, the point is I don't want to use

Streamwriter only writes a certain amount of bytes from a string list

爷,独闯天下 提交于 2021-02-10 13:15:54
问题 I have 27 csv files containing employee timesheet data with about 2000 lines of data in total, and is growing day by day. I am writing an application that compiles the data in each file to a single csv file for analysis in Excel. I do this by reading each file, write its contents to a string list and then write the string list to a new file. Below is the code writing the list to the file: FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.CreateNew, FileAccess.ReadWrite);