Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List Overlap Trouble
#1
Hey Guys!
I am given an exercise to solve . Its about list overlap and random generating of lists and to return a list that contains only the elements that are common between the lists .
I am done with this part and I succeeded in it . but about this extra part : Randomly generate two lists to test this , I have tried many ways doing this but unfortunately I stuck into trouble .
import random


def RAND(start, finish, num):
    third_list = []

    for c in range(num):
        third_list.append(random.randint(start, finish))

    return third_list


num = 5
start = 1
finish = 50
print(RAND(start, finish, num))


def RAND2(strt, fin, n):
    fourth_list = []

    for m in range(n):
        fourth_list.append(random.randint(strt, fin))
    return fourth_list


n = 4
strt = 0
fin = 10
print(RAND2(strt, fin, n))

for char in third_list:
    for char2 in fourth_list:
        if char == char2:
            print('This value ** {0} ** of random lists are the same ! '.format(char))

This is my code which includes two random lists and a for loop for taking same elements in both of them .
But at line 32 and 33 I got an error while defining name of random lists which I defined earlier .
So , I hope that you can help me get along with this code finally .
Thanks
Reply


Messages In This Thread
List Overlap Trouble - by erfanakbari1 - Mar-18-2019, 12:47 PM
RE: List Overlap Trouble - by ichabod801 - Mar-18-2019, 02:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  List Overlap Josh_Python890 4 2,609 Jun-12-2019, 03:23 PM
Last Post: kotter

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020