-1

This is my code

string='AABCAAADA'
k=3
for i in range(0,len(string),k):
    print(set(string[i:i+k]))

each time I run it produces a different output. how can i fix this?
outputs:

{'B', 'A'}
{'A', 'C'}
{'D', 'A'}
{'B', 'A'}
{'C', 'A'}
{'D', 'A'}
{'A', 'B'}
{'A', 'C'}
{'A', 'D'}
1
  • 3
    That is outputting the same sets. Set objects are inherently unordered. Commented Jan 23, 2020 at 8:20

1 Answer 1

1

Because set() returns set, which by design is unordered collection.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.