-5

In my code I have following line:

STYLE_CHOICES = sorted((item, item) for item in get_all_styles())

And I just can't understand why there is (item, item) for ... instead for example item for ...

This code snippet is from http://www.django-rest-framework.org/tutorial/1-serialization/#creating-a-model-to-work-with

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
strang1ato
  • 37
  • 6
  • 2
    It will be helpful if you can provide sample IN/OUT for your particular problem. – Marcus.Aurelianus Jul 29 '18 at 08:44
  • I gave you whole code. – strang1ato Jul 29 '18 at 08:49
  • 2
    What precisely don't you understand? The syntax? `item for ...` would give you a sorted list of items. `(item, item) for ...` gives you a sorted list of *two-tuples*, where both values in each tuple are the same. – jonrsharpe Jul 29 '18 at 09:08
  • So why I need a sorted list of two-tuples instead sorted list of one-tuple? – strang1ato Jul 29 '18 at 09:17
  • The first version isn't a sorted list of one-tuples, that would be `(item,) for ...`. As to why you need two-tuples: presumably, that's what the API of the library you're using requires. – jonrsharpe Jul 29 '18 at 10:33

1 Answers1

0

Please see this question.

It's looks like you need a collection of tuples (value, label) as chooses for the CharField model. In your case, the value and the label are the same.

Moshe Simantov
  • 3,937
  • 2
  • 25
  • 35