Contest SET Data Type RELATED QUERY

Discussion in 'Big Data and Analytics' started by Ved Prakash_7, Jul 18, 2019.

  1. Ved Prakash_7

    Ved Prakash_7 Member

    Joined:
    Jun 26, 2019
    Messages:
    9
    Likes Received:
    3
    When i write
    print(set("good")) then it's giving output as
    {'o' , 'd' , 'g'} Screenshot 2019-07-18 at 6.44.45 PM.png

    & when i am writing
    print(set("dog"))
    then it gives output as
    { 'd' ,'o' ,'g'}
    Screenshot 2019-07-18 at 6.45.32 PM.png

    Can anyone please help me to understand why this is happening ,why in case of 1st one the output is not
    { 'g' ,'o' ,'d'}
     
    #1
    SUNNY BHAVEEN CHANDRA likes this.
  2. SUNNY BHAVEEN CHANDRA

    SUNNY BHAVEEN CHANDRA Well-Known Member

    Joined:
    Feb 4, 2019
    Messages:
    56
    Likes Received:
    8
    Hi Ved,

    As per the formal definition of sets -
    " A set is an unordered collection of objects without duplicates."
    So sets are data structures (and mathematical concepts) that do not preserve the element order and the same is implemented in python that's why you are getting such output.
    Following are some more examples from my trials -

    upload_2019-7-19_12-37-43.png

    I hope this answered your query.

    Regards,
    Sunny,
    Teaching Assistant
     
    #2
    Ved Prakash_7 likes this.
  3. Ved Prakash_7

    Ved Prakash_7 Member

    Joined:
    Jun 26, 2019
    Messages:
    9
    Likes Received:
    3
    yes i got my answer , thank you so much .
     
    #3
    SUNNY BHAVEEN CHANDRA likes this.

Share This Page