Home > other >  Python consult
Python consult

Time:09-28

Why this collection of elements in the print out automatically after sorting and pop has been I add 0 delete??

CodePudding user response:

You use the set, the default will be sorting, is the first set of pop to delete, so delete 0,

If you don't want to sort with the list, the list by default pop last one, you can specify the location of pop, such as pop first number_list. Pop (0)

CodePudding user response:

reference 1/f, ice all over the sky the wind response:
set, you use the default sort, is the first set of pop to delete, so delete 0,

If you don't want to sort with the list, the list by default pop last one, you can specify the location of pop, such as pop first number_list. Pop (0)

Not to say that the collection is disorderly? And when one or more elements will not sort after numerical larger such as "99", is this why?

CodePudding user response:

reference 1/f, ice all over the sky the wind response:
set, you use the default sort, is the first set of pop to delete, so delete 0,

If you don't want to sort with the list, the list by default pop last one, you can specify the location of pop, such as pop first number_list. Pop (0)

And in the collection pop is indeed random deletable

CodePudding user response:

Yes, I said is wrong, the set is unordered, such as operating in this way, each time the print order is different, so the pop is which number is random, but must be printed before the first
 
Number_set={' 2 ', '1', '5', '7', '3'}
Print (number_set)
Number_set. Add (' 0 ')
Print (number_set)
Number_set. Pop ()
Print (number_set)

All Numbers look every time the value of the relative order is fixed, and set there are relations to implement a hash, such as number_set=,2,3,32 {1}, 32 is fixed in the first, and then add 0 is fixed in the final, when pop is only 32, so pure is difficult to achieve the desired random Numbers
  • Related