CopyPastor

Detecting plagiarism made easy.

Score: 0.8013009428977966; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2020-09-29
by inspectorG4dget

Original Post

Original - Posted on 2015-07-06
by Kasravnd



            
Present in both answers; Present only in the new answer; Present only in the old answer;

In [86]: df Out[86]: Name Hobbies 0 Paul [NBA, PS4] 1 Jeff [Hockey, Read, PS4] 2 Kyle [Sleep, NBA] In [87]: df['dummy'] = 1 In [88]: df.explode("Hobbies").pivot(index='Name', columns='Hobbies', values='dummy').fillna(value=0) Out[88]: Hobbies Hockey NBA PS4 Read Sleep Name Jeff 1.0 0.0 1.0 1.0 0.0 Kyle 0.0 1.0 0.0 0.0 1.0 Paul 0.0 1.0 1.0 0.0 0.0

For cases with a low number of lists you can simply add the lists together or use in-place unpacking (available in Python-3.5+):
In [1]: listone = [1, 2, 3] ...: listtwo = [4, 5, 6] In [2]: listone + listtwo Out[2]: [1, 2, 3, 4, 5, 6] In [3]: [*listone, *listtwo] Out[3]: [1, 2, 3, 4, 5, 6]


As a more general way for cases with more number of lists, as a pythonic approach, you can use `chain.from_iterable()`<sup>1</sup> function from `itertoold` module. Also, based on [*this* answer][1] this function is the best; or at least a very food way for flatting a nested list as well.
>>> l=[[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> import itertools >>> list(itertools.chain.from_iterable(l)) [1, 2, 3, 4, 5, 6, 7, 8, 9]
----------
<sub> 1. Note that `chain.from_iterable()` is available in Python 2.6 and later. In other versions, use `chain(*l)`. </sub>
[1]: https://stackoverflow.com/a/953097/2867928


        
Present in both answers; Present only in the new answer; Present only in the old answer;