Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I'm somewhat befuddled in regards to a data structure in python; (),[], and {}. I'm attempting to sort a straightforward list, most likely since I can't distinguish the kind of information I am neglecting to sort it. 

My List: ['Stem', 'constitute', 'Sedge', 'Eflux', 'Whim', 'Intrigue']

My inquiry is what kind of information this is, and how to sort the words one after another in order?

1 Answer

0 votes
by (26.4k points)


[] denotes list

() denotes a tuple

{} denotes a dictionary

You should investigate the authority Python tutorial as these are the actual rudiments of programming in Python. 

What you have is a rundown/list of strings. You can also sort it like this:

In [1]: lst = ['Stem', 'constitute', 'Sedge', 'Eflux', 'Whim', 'Intrigue']

In [2]: sorted(lst)

Out[2]: ['Eflux', 'Intrigue', 'Sedge', 'Stem', 'Whim', 'constitute']

As should be obvious, words that start with a capitalized letter get inclination over those beginning with a lowercase letter. On the off chance that you need to sort them autonomously, do this 

In [4]: sorted(lst, key=str.lower)

Out[4]: ['constitute', 'Eflux', 'Intrigue', 'Sedge', 'Stem', 'Whim']

You can likewise sort the rundown in turn around the request by doing this:

In [12]: sorted(lst, reverse=True)

Out[12]: ['constitute', 'Whim', 'Stem', 'Sedge', 'Intrigue', 'Eflux']

In [13]: sorted(lst, key=str.lower, reverse=True)

Out[13]: ['Whim', 'Stem', 'Sedge', 'Intrigue', 'Eflux', 'constitute']

Join the python online course fast, to learn python concepts in detail and get certified.

For more details, do check out the below video tutorial...

Related questions

0 votes
2 answers
asked Oct 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Aug 6, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Aug 1, 2019 in Python by Sammy (47.6k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.6k users

Browse Categories