0

letter={'s', 'a', 'i', 'j', 'o', 'n'} print(letters.remove('i')) showing error. How to write it exact way? And explainto reverse

20th May 2017, 3:42 PM
sai charan tej
sai charan tej - avatar
5 Antworten
+ 1
try to replace curses brackets by squares brackets (list) use curses brackets to define a dictionary with key: value
20th May 2017, 6:59 PM
MBZH31
MBZH31 - avatar
+ 6
There is a misspelling in your code. You declared 'letter' set and you try to run a method on 'letters'. It should go like this: letters={'s', 'a', 'i', 'j', 'o', 'n'} letters.remove('i') print(letters) reverse() can't be applied on sets, as they are variables of an unordered type.
20th May 2017, 3:52 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
This is a set. As a type, it is unordered and can carry unique values only. When printed though, it usually is displayed in an ordered fashion. But that is not its intrinsic trait - it is probably somehow knit into __repr__ or __str__ method which are used by print(). Try to create a set of unique values of different types. You'll see that it is 'out of order' ;)
20th May 2017, 4:16 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Kuba.. This lead me to a question.. Why does this letter={'s', 'a', 'i', 'j', 'o', 'n'} print(letter) give the following output? {'a', 'i', 'j', 'o', 'n', 's'} Why move the first element to the end?
20th May 2017, 4:13 PM
LordHill
LordHill - avatar
0
I see.. changing a few elements to ints piled the ints together.. So out of order, in a somewhat orderly fashion.. Interesting...
20th May 2017, 4:26 PM
LordHill
LordHill - avatar