Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1171
test python
Active
Public
Actions
Authored by
aarwine
on Jun 5 2014, 12:00 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F163443: test_python
Jun 5 2014, 12:00 AM
2014-06-05 00:00:58 (UTC+0)
Subscribers
None
#!/usr/bin/python2
def
commonInLists
(
listOfLists
):
# Input: List of lists
# Output: Single list of common elements
# Must take unknown number of lists
if
len
(
listOfLists
)
==
0
:
raise
Exception
(
'No.'
)
elif
len
(
listOfLists
)
==
1
:
return
listOfLists
[
0
]
elif
len
(
listOfLists
)
==
2
:
return
list
(
set
(
listOfLists
[
0
])
.
intersection
(
listOfLists
[
1
]))
elif
len
(
listOfLists
)
>
2
:
result
=
set
(
listOfLists
[
0
])
.
intersection
(
listOfLists
[
1
])
for
i
in
range
(
2
,
len
(
listOfLists
)):
result
=
result
.
intersection
(
listOfLists
[
i
])
return
result
else
:
raise
Exception
(
'How did I get here?'
)
a
=
[
'1'
,
'2'
,
'3'
,
'4'
,
'5'
]
b
=
[
'2'
,
'3'
,
'4'
,
'5'
,
'6'
]
c
=
[
'3'
,
'4'
,
'5'
,
'6'
,
'7'
]
d
=
[
'4'
,
'5'
,
'6'
,
'7'
,
'8'
]
foo
=
[
a
,
b
,
c
,
d
]
print
commonInLists
(
foo
)
Event Timeline
aarwine
edited the content of this paste.
(Show Details)
Jun 5 2014, 12:00 AM
2014-06-05 00:00:58 (UTC+0)
aarwine
changed the title of this paste from untitled to
test python
.
aarwine
updated the paste's language from
autodetect
to
python
.
Log In to Comment