0

I have list 2 which has all the items fron list 1 and x :

 import random
 for x in range(10):
 print(random.randint(1,101))

 list1 = ''
 list.append(x)
 list2 = list1

How can I create a set and add all the items from list 2 into a set? All the code up to this point is what I have been told to do and I have no idea how to create a set and append items to it.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 3
    You can make a set from any iterable by doing `set(list2)`. (Note that this creates a new `set` object, it doesn't turn `list2` into a `set`) The code you posted here has a lot of problems, not the least of which is that you don't define any lists in it. – Patrick Haugh May 30 '18 at 17:03
  • soz yh code wouldnt post in original form idk y so i edited it a bit –  May 30 '18 at 17:10
  • Possible duplicate of [How to construct a set out of list items in python?](https://stackoverflow.com/questions/15768757/how-to-construct-a-set-out-of-list-items-in-python) – Jeff Learman May 30 '18 at 18:17
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer May 31 '18 at 00:40

1 Answers1

0

Maybe something like this. I convert list to set in the end.

  #!/usr/bin/env python
    # -*- coding: utf-8 -*-


    import random
    list1 = []

    for x in range(10):
        number = random.randint(1,101)
        list1.append(number)


    list2 = list1
    new_set = set(list2)
    print (new_set)
TomRavn
  • 1,134
  • 14
  • 30