0

I am trying to create a tuple as:

tuples = (i+1,
          db.entries[i].get("ENTRYTYPE"),
          db.entries[i].get("ID"),
          db.entries[i].get("title"),
          db.entries[i].get("author"),
          db.entries[i].get("journal"),
          db.entries[i].get("year")
          )

where db is a database, i is properly defined.

Now, the get("text") has ~40 different text. I can do it manually, and it is working. But is it possible to do it in some other way, e.g. loop like:

Entries = ["ENTRYTYPE", "ID", "title", "author" ...]
for entry in entries:
  tuples = (i+1, db.entries.get(entry)
4
  • 2
    Why not just use a list? Commented Jan 26, 2016 at 19:28
  • Actually, I will get some values empty. And I need to keep the order. Commented Jan 26, 2016 at 19:31
  • What? Please update your question with more information and some test data. Commented Jan 26, 2016 at 19:35
  • You can't have empty places in tuple. You have to put None or something other in empty places. And you can do the same with list. Commented Jan 26, 2016 at 19:38

2 Answers 2

2

Should be as simple as tuples = (i+1,) + tuple(db.entries.get(e) for e in Entries)

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

Comments

1

If you really need a tuple, try this:

tuples = tuple([i+1] + [db.entries.get(entry) for entry in entries])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.