Category:2007 albums
Category:P-Funk albums
Category:SarscapeQ:
Create a new list for each value of a key in a list
I have a list of strings that contain several lists, but I need to add a new column, only for values of a given key.
example:
l = ['2018-02-14','2017-02-20','2017-01-04','2017-02-08','2017-01-13']
The result should be:
[['2018-02-14'],['2017-02-20'],['2017-01-04'],['2017-02-08'],['2017-01-13']]
I have tried:
import itertools
import pandas as pd
l = ['2018-02-14','2017-02-20','2017-01-04','2017-02-08','2017-01-13']
final = []
for x in l:
for i in x:
final.append(i)
print(final)
A:
I think the best you can do is use enumerate like:
import itertools
import pandas as pd
l = ['2018-02-14','2017-02-20','2017-01-04','2017-02-08','2017-01-13']
new_list = [l[idx[0]]:l[idx[1]] for idx in enumerate(itertools.chain.from_iterable(list(itertools.chain.from_iterable(s) for s in l)))
final = list(new_list)
print(final)
Output:
[[2018-02-14], ['2017-02-20'], ['2017-01-04'], ['2017-02-08'], ['2017-01-13']]
On Saturday, I sat at a friend’s house with a dozen slices of bread and assorted toppings. I worked through a dozen slices to eat the rest of the bread.
I can’t help it, and I can’t predict when this will happen, but sometimes I have a grand idea to make a run at the 16-inch ruler. The scenario is always the be359ba680
Related links:
Comentarios