Is set an indexed and ordered data type? If not then how do you actually access data from a set?

Question

I have a set with 4 values i.e. A,B,C, and D

If I print the set again after assigning the values, will it show the values in the same order?

If the values are not indexed then how to access these values?

solved 0
TheDataMonk 3 years 18 Answers 892 views Grand Master 0

Answers ( 18 )

  1. Set is an unordered type. If we want to access data from the set, we convert it into a list and then access them by indexing.

  2. Sets are non indexed and unordered , but sets you can use loops to iterate through set elements.

    S =set(A,B,C,D)
    For i in s:
    Print(i)
    A
    B
    C
    D

  3. Set is a collection that is unordered and unindexed.
    But working on it, I found when data types in sets are-
    1) Numbers – the values after print; get arranged in ascending order.
    2) Boolean(True or False)- the values after print arrange in ascending order.
    3) String- every time we print the set, we get the set value arranged in a different order.
    If the values are not indexed, then we can use the iterator method for accessing it.

  4. Set is a collection that is unordered and unindexed.
    But working on it, I found when data types in sets are-
    1) Numbers – the values after print; get arranged in ascending order.
    2) Boolean(True or False)- the values after print arrange in ascending order.
    3) String- every time we print the set, we get the set value arranged in a different order.

    If the values are not indexed, then we can use the iterator method for accessing it.

  5. Set is unordered. We cant access elements of set by index. We can get the list of elements by looping over the set.

  6. Set is unordered and we can access the elements using list and not by set. Data types do get arranged in ascendng order for int, string etc.

  7. The Values will appear in the same order as they are in alphabetical (A-Z) order already. Had they not been in order, the output would have been reordered alphabetically.

    The set can be converted to a list and the elements therein can be accessed after that

  8. Set is a unique unordered (items have no index) collection of data which is iterable and mutable.
    The following ways can be used to get the elements-
    1. Looping over the set with the help of for loop
    2. Converting the set into a list-
    set1= {“Hi” , “are”, “you”}
    s= list(set1)
    s[1]
    The output is ‘you’ , because the set gets converted into a list with elements in random order which is maintained everytime you run it.

    Best answer
  9. set is non indexed and un ordered.
    It can be accessed by for loop.
    for i in set:
    print(i)

  10. Set is an unordered data type in python so we can’t access the values of the set one by one.
    s = set(‘a’, ‘b’, ‘c’)

    Although we have two options –
    1. Convert set into a list and then access one by one.
    l = list(s)
    first = l[0]

    2. Using for loop.
    for i in s:
    print(i)

    Thank you

  11. Sets are un indexed and in ordered. To access them we need to loop them using ‘in ‘ keyword

  12. Set consists of unordered data , hence it values cannot be accessed by indexing. We can either loop through the values of set or access them by converting it to lists.

  13. A set is unordered and unindexed and can be accessed by either converting to a list or simply printing the elements in it through a for loop.

  14. No, the set is not indexed and ordered data type.
    By ordered data type, we mean the order in which the items are inserted/updated in the list and we receive the elements of the list in the same way.
    By indexed data type, we mean extracting data from the list based on its position.
    But, since the set is neither ordered nor indexed, its values cannot be retrieved in the same order, and neither can we extract the elements of the set based on the position.
    So, now the question is how to access the elements of the set.
    For that, we can simply run a for loop to extract all the elements of the set.
    For instance,

    set=([“People”, “of”, “India”, “are”, “kind-hearted”])
    for i in set:
    print(“The elements of the set are:n”, i,end=” “)

  15. Python does not provide us with a way of accessing an individual set item. However, we can use a for loop to iterate through all the items of a set. For example.
    Suppose I have a set with 4 values i.e. A,B,C, and D
    We can get the list of elements by looping over the set
    A = set([” A”,”B” ,”C”, “D”])
    for m in A:
    print(m)

  16. Set is unordered and Set cannot be accessed by referring to index.
    1).To access elements in set we need to use loop(for)
    2).Convert them to list then access by referring to index
    3).Also we can use (in) to check if a given element is present in a set

  17. No a set is not indexed and ordered, so it will not print the elements in the same order again. The values of a set is taken as together, like you can check if some element is in the set or not but you cannot determine its position.

  18. Set items are unordered it cannot be accssed by index.
    But we access it by using loop

Leave an answer

Browse
Browse