Insert element in Python list after every nth element

I’ve got two one liners. Given: >>> letters = [‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’] Use enumerate to get index, add ‘x’ every 3rd letter, eg: mod(n, 3) == 2, then concatenate into string and list() it. >>> list(”.join(l + ‘x’ * (n % 3 == 2) for n, l in enumerate(letters))) [‘a’, ‘b’, ‘c’, ‘x’, ‘d’, ‘e’, ‘f’, ‘x’, … Read more

Get the index (counter) of an ‘ng-repeat’ item with AngularJS?

Angularjs documentation is full of examples, you just need to take some time and explore it. See this example here : ngRepeat example , it’s the same case. <ul> <li ng-repeat=”question in questions | filter: {questionTypesId: questionType, selected: true}”> <div> <span class=”name”> {{$index + 1}} {{ question.questionText }} </span> </div> <ul> <li ng-repeat=”answer in question.answers”> … Read more

Do NoSQL databases use or need indexes?

CouchDB and MongoDB definitely yes. I mentioned that in my book: http://use-the-index-luke.com/sql/testing-scalability/response-time-throughput-scaling-horizontal Here are the respective docs: http://guide.couchdb.org/draft/btree.html http://www.mongodb.org/display/DOCS/Indexes NoSQL is, however, too fragmented to give a definite “yes, all NoSQL systems need indexes”, I believe. Most systems require and provide indexes but not at level most SQL databases do. Recently, the Cassandra people were … Read more

Entity Framework 6.1 – Create index with INCLUDE statement

Strictly speaking it has been always possible in Code First Migrations because you can run sql in a migration: public partial class AddIndexes : DbMigration { private const string IndexName = “IX_LogSamples”; public override void Up() { Sql(String.Format(@”CREATE NONCLUSTERED INDEX [{0}] ON [dbo].[Logs] ([SampleId],[Date]) INCLUDE ([Value])”, IndexName)); } public override void Down() { DropIndex(“dbo.Logs”, IndexName); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)