How can you split an input to go into 2 different lists using a ;











up vote
0
down vote

favorite












Ive been given a problem where given two lists, returns the list of all the elements that occur multiple times in both lists. The returned list should be in ascending order, without duplicates. Your main program will allow the enter two lists of numbers on one line separated by a semicolon and end input with a blank line. For example



Lists: 1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3



List1: 1 3 4 2 1 2 1 3



List 2: 4 4 2 4 3 2 4 4 3 1 3



The result for this example would be: [2, 3]



I have a majority of the programming working, its just that after implementing the first for loop in the calculator function, I get an error.
ValueError: invalid literal for int() with base 10: '3;'



It may be a possibility that due to my inexperience there is a syntax error somewhere. Any help or advice is greatly appreciated.



def calculator(userinput):
marker = ":"

for x in userinput:
if x == ";":
marker = ";"
elif marker != ";":
numlist1 = [int(x) for x in userinput]
elif marker == ";": numlist2
numlist2 = [int(x) for x in userinput]
else:
pass

for y in numlist1:
list1 = numlist1.count(y)
list2 = numlist2.count(y)
if list1 > 1 and list2 > 1:
if y not in multiples:
multiples.append(int(y))
else:
continue

multiples.sort()
print(multiples)

while True:

multiples =

userinput = input("Lists: ").split() # asks for first input from user
if len(userinput) == 0: # breaks if user inputs nothing
break

calculator(userinput) # calls the calculator function









share|improve this question




















  • 1




    What error do you get? Why not update your question with the output you see when you run your script?
    – Red Cricket
    Nov 11 at 8:44












  • What output would you expect from the input in your example?
    – Red Cricket
    Nov 11 at 9:19










  • @RedCricket hi sorry, I edited my original post. Didn't think to post it.
    – Reese
    Nov 11 at 9:22















up vote
0
down vote

favorite












Ive been given a problem where given two lists, returns the list of all the elements that occur multiple times in both lists. The returned list should be in ascending order, without duplicates. Your main program will allow the enter two lists of numbers on one line separated by a semicolon and end input with a blank line. For example



Lists: 1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3



List1: 1 3 4 2 1 2 1 3



List 2: 4 4 2 4 3 2 4 4 3 1 3



The result for this example would be: [2, 3]



I have a majority of the programming working, its just that after implementing the first for loop in the calculator function, I get an error.
ValueError: invalid literal for int() with base 10: '3;'



It may be a possibility that due to my inexperience there is a syntax error somewhere. Any help or advice is greatly appreciated.



def calculator(userinput):
marker = ":"

for x in userinput:
if x == ";":
marker = ";"
elif marker != ";":
numlist1 = [int(x) for x in userinput]
elif marker == ";": numlist2
numlist2 = [int(x) for x in userinput]
else:
pass

for y in numlist1:
list1 = numlist1.count(y)
list2 = numlist2.count(y)
if list1 > 1 and list2 > 1:
if y not in multiples:
multiples.append(int(y))
else:
continue

multiples.sort()
print(multiples)

while True:

multiples =

userinput = input("Lists: ").split() # asks for first input from user
if len(userinput) == 0: # breaks if user inputs nothing
break

calculator(userinput) # calls the calculator function









share|improve this question




















  • 1




    What error do you get? Why not update your question with the output you see when you run your script?
    – Red Cricket
    Nov 11 at 8:44












  • What output would you expect from the input in your example?
    – Red Cricket
    Nov 11 at 9:19










  • @RedCricket hi sorry, I edited my original post. Didn't think to post it.
    – Reese
    Nov 11 at 9:22













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Ive been given a problem where given two lists, returns the list of all the elements that occur multiple times in both lists. The returned list should be in ascending order, without duplicates. Your main program will allow the enter two lists of numbers on one line separated by a semicolon and end input with a blank line. For example



Lists: 1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3



List1: 1 3 4 2 1 2 1 3



List 2: 4 4 2 4 3 2 4 4 3 1 3



The result for this example would be: [2, 3]



I have a majority of the programming working, its just that after implementing the first for loop in the calculator function, I get an error.
ValueError: invalid literal for int() with base 10: '3;'



It may be a possibility that due to my inexperience there is a syntax error somewhere. Any help or advice is greatly appreciated.



def calculator(userinput):
marker = ":"

for x in userinput:
if x == ";":
marker = ";"
elif marker != ";":
numlist1 = [int(x) for x in userinput]
elif marker == ";": numlist2
numlist2 = [int(x) for x in userinput]
else:
pass

for y in numlist1:
list1 = numlist1.count(y)
list2 = numlist2.count(y)
if list1 > 1 and list2 > 1:
if y not in multiples:
multiples.append(int(y))
else:
continue

multiples.sort()
print(multiples)

while True:

multiples =

userinput = input("Lists: ").split() # asks for first input from user
if len(userinput) == 0: # breaks if user inputs nothing
break

calculator(userinput) # calls the calculator function









share|improve this question















Ive been given a problem where given two lists, returns the list of all the elements that occur multiple times in both lists. The returned list should be in ascending order, without duplicates. Your main program will allow the enter two lists of numbers on one line separated by a semicolon and end input with a blank line. For example



Lists: 1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3



List1: 1 3 4 2 1 2 1 3



List 2: 4 4 2 4 3 2 4 4 3 1 3



The result for this example would be: [2, 3]



I have a majority of the programming working, its just that after implementing the first for loop in the calculator function, I get an error.
ValueError: invalid literal for int() with base 10: '3;'



It may be a possibility that due to my inexperience there is a syntax error somewhere. Any help or advice is greatly appreciated.



def calculator(userinput):
marker = ":"

for x in userinput:
if x == ";":
marker = ";"
elif marker != ";":
numlist1 = [int(x) for x in userinput]
elif marker == ";": numlist2
numlist2 = [int(x) for x in userinput]
else:
pass

for y in numlist1:
list1 = numlist1.count(y)
list2 = numlist2.count(y)
if list1 > 1 and list2 > 1:
if y not in multiples:
multiples.append(int(y))
else:
continue

multiples.sort()
print(multiples)

while True:

multiples =

userinput = input("Lists: ").split() # asks for first input from user
if len(userinput) == 0: # breaks if user inputs nothing
break

calculator(userinput) # calls the calculator function






python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 9:29

























asked Nov 11 at 8:30









Reese

11




11








  • 1




    What error do you get? Why not update your question with the output you see when you run your script?
    – Red Cricket
    Nov 11 at 8:44












  • What output would you expect from the input in your example?
    – Red Cricket
    Nov 11 at 9:19










  • @RedCricket hi sorry, I edited my original post. Didn't think to post it.
    – Reese
    Nov 11 at 9:22














  • 1




    What error do you get? Why not update your question with the output you see when you run your script?
    – Red Cricket
    Nov 11 at 8:44












  • What output would you expect from the input in your example?
    – Red Cricket
    Nov 11 at 9:19










  • @RedCricket hi sorry, I edited my original post. Didn't think to post it.
    – Reese
    Nov 11 at 9:22








1




1




What error do you get? Why not update your question with the output you see when you run your script?
– Red Cricket
Nov 11 at 8:44






What error do you get? Why not update your question with the output you see when you run your script?
– Red Cricket
Nov 11 at 8:44














What output would you expect from the input in your example?
– Red Cricket
Nov 11 at 9:19




What output would you expect from the input in your example?
– Red Cricket
Nov 11 at 9:19












@RedCricket hi sorry, I edited my original post. Didn't think to post it.
– Reese
Nov 11 at 9:22




@RedCricket hi sorry, I edited my original post. Didn't think to post it.
– Reese
Nov 11 at 9:22












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I believe this does what you want …



$ cat intersec_two_list.py
#!/bin/env python

import sys
import collections

def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))

def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)

def main(l1,l2):
print find_mult(l1,l2)

if __name__ == "__main__":
user_input = sys.argv[1:][0]
[s1, s2] = user_input.split(';')
s1 = s1.strip()
s2 = s2.strip()
l1 = s1.split(' ')
l2 = s2.split(' ')
main(l1,l2)


You would execute like so ...



$ ./intersec_two_list.py "1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3"
['2', '3']


Here is some explanation of the code above:



def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))


In this method I set() to remove duplications from the lists.



>>> list = [ 1,2,3,3,3,3,4,5,6,6,6]
>>> set(list)
{1, 2, 3, 4, 5, 6}


Then we use & like so set(lst1) & set(lst2) to get a intersection of the two sets then convert that back to a list with list(set(lst1) & set(lst2)) and then we return a sorted list.



In this method …



def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)


… use make use of Counter's. What a counter does is this:



>>> from collections import Counter
>>> list1 = [1,2,3,3,3,3,4,5,6,6,6]
>>> Counter(list1)
>>> Counter({3: 4, 6: 3, 1: 1, 2: 1, 4: 1, 5: 1})


It counts the elements of a list. This way we can get rid of all the elements in out list that did not occur more than once like so:



mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]


The above is list comprehension which a short had for this python code:



mc1 = 
for mc in c1.items():
if mc[1] > 1:
mc1.append(mc[0])


Then key to above code is c1.items(). c1 is a collection and collections have a method items() which return a list of (elem, cnt) pairs from the collections. So if mc[1] > 1 means the element occurred more than once and mc[0] is the element. We save these elements in a list called mc1.



We do the same process on lst2. We create collection, c2 and create a list mc2. Now we get the intersection of mc1 and mc2 and return that and BAM! your done.






share|improve this answer























  • I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
    – Mr. T
    Nov 11 at 9:12










  • Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
    – Red Cricket
    Nov 11 at 9:18










  • Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
    – Reese
    Nov 11 at 9:29











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247040%2fhow-can-you-split-an-input-to-go-into-2-different-lists-using-a%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













I believe this does what you want …



$ cat intersec_two_list.py
#!/bin/env python

import sys
import collections

def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))

def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)

def main(l1,l2):
print find_mult(l1,l2)

if __name__ == "__main__":
user_input = sys.argv[1:][0]
[s1, s2] = user_input.split(';')
s1 = s1.strip()
s2 = s2.strip()
l1 = s1.split(' ')
l2 = s2.split(' ')
main(l1,l2)


You would execute like so ...



$ ./intersec_two_list.py "1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3"
['2', '3']


Here is some explanation of the code above:



def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))


In this method I set() to remove duplications from the lists.



>>> list = [ 1,2,3,3,3,3,4,5,6,6,6]
>>> set(list)
{1, 2, 3, 4, 5, 6}


Then we use & like so set(lst1) & set(lst2) to get a intersection of the two sets then convert that back to a list with list(set(lst1) & set(lst2)) and then we return a sorted list.



In this method …



def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)


… use make use of Counter's. What a counter does is this:



>>> from collections import Counter
>>> list1 = [1,2,3,3,3,3,4,5,6,6,6]
>>> Counter(list1)
>>> Counter({3: 4, 6: 3, 1: 1, 2: 1, 4: 1, 5: 1})


It counts the elements of a list. This way we can get rid of all the elements in out list that did not occur more than once like so:



mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]


The above is list comprehension which a short had for this python code:



mc1 = 
for mc in c1.items():
if mc[1] > 1:
mc1.append(mc[0])


Then key to above code is c1.items(). c1 is a collection and collections have a method items() which return a list of (elem, cnt) pairs from the collections. So if mc[1] > 1 means the element occurred more than once and mc[0] is the element. We save these elements in a list called mc1.



We do the same process on lst2. We create collection, c2 and create a list mc2. Now we get the intersection of mc1 and mc2 and return that and BAM! your done.






share|improve this answer























  • I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
    – Mr. T
    Nov 11 at 9:12










  • Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
    – Red Cricket
    Nov 11 at 9:18










  • Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
    – Reese
    Nov 11 at 9:29















up vote
0
down vote













I believe this does what you want …



$ cat intersec_two_list.py
#!/bin/env python

import sys
import collections

def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))

def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)

def main(l1,l2):
print find_mult(l1,l2)

if __name__ == "__main__":
user_input = sys.argv[1:][0]
[s1, s2] = user_input.split(';')
s1 = s1.strip()
s2 = s2.strip()
l1 = s1.split(' ')
l2 = s2.split(' ')
main(l1,l2)


You would execute like so ...



$ ./intersec_two_list.py "1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3"
['2', '3']


Here is some explanation of the code above:



def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))


In this method I set() to remove duplications from the lists.



>>> list = [ 1,2,3,3,3,3,4,5,6,6,6]
>>> set(list)
{1, 2, 3, 4, 5, 6}


Then we use & like so set(lst1) & set(lst2) to get a intersection of the two sets then convert that back to a list with list(set(lst1) & set(lst2)) and then we return a sorted list.



In this method …



def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)


… use make use of Counter's. What a counter does is this:



>>> from collections import Counter
>>> list1 = [1,2,3,3,3,3,4,5,6,6,6]
>>> Counter(list1)
>>> Counter({3: 4, 6: 3, 1: 1, 2: 1, 4: 1, 5: 1})


It counts the elements of a list. This way we can get rid of all the elements in out list that did not occur more than once like so:



mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]


The above is list comprehension which a short had for this python code:



mc1 = 
for mc in c1.items():
if mc[1] > 1:
mc1.append(mc[0])


Then key to above code is c1.items(). c1 is a collection and collections have a method items() which return a list of (elem, cnt) pairs from the collections. So if mc[1] > 1 means the element occurred more than once and mc[0] is the element. We save these elements in a list called mc1.



We do the same process on lst2. We create collection, c2 and create a list mc2. Now we get the intersection of mc1 and mc2 and return that and BAM! your done.






share|improve this answer























  • I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
    – Mr. T
    Nov 11 at 9:12










  • Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
    – Red Cricket
    Nov 11 at 9:18










  • Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
    – Reese
    Nov 11 at 9:29













up vote
0
down vote










up vote
0
down vote









I believe this does what you want …



$ cat intersec_two_list.py
#!/bin/env python

import sys
import collections

def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))

def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)

def main(l1,l2):
print find_mult(l1,l2)

if __name__ == "__main__":
user_input = sys.argv[1:][0]
[s1, s2] = user_input.split(';')
s1 = s1.strip()
s2 = s2.strip()
l1 = s1.split(' ')
l2 = s2.split(' ')
main(l1,l2)


You would execute like so ...



$ ./intersec_two_list.py "1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3"
['2', '3']


Here is some explanation of the code above:



def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))


In this method I set() to remove duplications from the lists.



>>> list = [ 1,2,3,3,3,3,4,5,6,6,6]
>>> set(list)
{1, 2, 3, 4, 5, 6}


Then we use & like so set(lst1) & set(lst2) to get a intersection of the two sets then convert that back to a list with list(set(lst1) & set(lst2)) and then we return a sorted list.



In this method …



def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)


… use make use of Counter's. What a counter does is this:



>>> from collections import Counter
>>> list1 = [1,2,3,3,3,3,4,5,6,6,6]
>>> Counter(list1)
>>> Counter({3: 4, 6: 3, 1: 1, 2: 1, 4: 1, 5: 1})


It counts the elements of a list. This way we can get rid of all the elements in out list that did not occur more than once like so:



mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]


The above is list comprehension which a short had for this python code:



mc1 = 
for mc in c1.items():
if mc[1] > 1:
mc1.append(mc[0])


Then key to above code is c1.items(). c1 is a collection and collections have a method items() which return a list of (elem, cnt) pairs from the collections. So if mc[1] > 1 means the element occurred more than once and mc[0] is the element. We save these elements in a list called mc1.



We do the same process on lst2. We create collection, c2 and create a list mc2. Now we get the intersection of mc1 and mc2 and return that and BAM! your done.






share|improve this answer














I believe this does what you want …



$ cat intersec_two_list.py
#!/bin/env python

import sys
import collections

def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))

def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)

def main(l1,l2):
print find_mult(l1,l2)

if __name__ == "__main__":
user_input = sys.argv[1:][0]
[s1, s2] = user_input.split(';')
s1 = s1.strip()
s2 = s2.strip()
l1 = s1.split(' ')
l2 = s2.split(' ')
main(l1,l2)


You would execute like so ...



$ ./intersec_two_list.py "1 3 4 2 1 2 1 3; 4 4 2 4 3 2 4 4 3 1 3"
['2', '3']


Here is some explanation of the code above:



def intersect_list(lst1, lst2):
return sorted(list(set(lst1) & set(lst2)))


In this method I set() to remove duplications from the lists.



>>> list = [ 1,2,3,3,3,3,4,5,6,6,6]
>>> set(list)
{1, 2, 3, 4, 5, 6}


Then we use & like so set(lst1) & set(lst2) to get a intersection of the two sets then convert that back to a list with list(set(lst1) & set(lst2)) and then we return a sorted list.



In this method …



def find_mult(lst1, lst2):
c1 = collections.Counter(lst1)
mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]
c2 = collections.Counter(lst2)
mc2 = [mc[0] for mc in c2.items() if mc[1] > 1]
return intersect_list(mc1, mc2)


… use make use of Counter's. What a counter does is this:



>>> from collections import Counter
>>> list1 = [1,2,3,3,3,3,4,5,6,6,6]
>>> Counter(list1)
>>> Counter({3: 4, 6: 3, 1: 1, 2: 1, 4: 1, 5: 1})


It counts the elements of a list. This way we can get rid of all the elements in out list that did not occur more than once like so:



mc1 = [mc[0] for mc in c1.items() if mc[1] > 1]


The above is list comprehension which a short had for this python code:



mc1 = 
for mc in c1.items():
if mc[1] > 1:
mc1.append(mc[0])


Then key to above code is c1.items(). c1 is a collection and collections have a method items() which return a list of (elem, cnt) pairs from the collections. So if mc[1] > 1 means the element occurred more than once and mc[0] is the element. We save these elements in a list called mc1.



We do the same process on lst2. We create collection, c2 and create a list mc2. Now we get the intersection of mc1 and mc2 and return that and BAM! your done.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 10:18

























answered Nov 11 at 9:09









Red Cricket

4,09183381




4,09183381












  • I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
    – Mr. T
    Nov 11 at 9:12










  • Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
    – Red Cricket
    Nov 11 at 9:18










  • Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
    – Reese
    Nov 11 at 9:29


















  • I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
    – Mr. T
    Nov 11 at 9:12










  • Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
    – Red Cricket
    Nov 11 at 9:18










  • Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
    – Reese
    Nov 11 at 9:29
















I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
– Mr. T
Nov 11 at 9:12




I understand "elements that occur multiple times in both lists" as "elements that occur multiple times in the first list and multiple times in the second list".
– Mr. T
Nov 11 at 9:12












Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
– Red Cricket
Nov 11 at 9:18




Yeah "occur multiple times in each list" well does that mean "occur more than once in both lists" or is once enough since 1 can me considered a multiple :)
– Red Cricket
Nov 11 at 9:18












Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
– Reese
Nov 11 at 9:29




Yeah @Mr.T that is how the question is meant to be interpreted it. I should've been more specific when I wrote down the problem.
– Reese
Nov 11 at 9:29


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247040%2fhow-can-you-split-an-input-to-go-into-2-different-lists-using-a%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine