Daily Python Puzzle

How to Modify a Sequence While Iterating over It (in Python)?

What is the output of this code snippet?   words = ['cat', 'mouse', 'dog'] for w in words[:]: if len(w) > 3: words.insert(0, w) print(words[0])   How to modify a sequence while iterating over it? For example, you want to prepare a data set of house prices for a machine learning algorithm to predict the …

How to Modify a Sequence While Iterating over It (in Python)? Read More »

Arbitrary Argument Lists, String Concatenation, and the Join Function in Python

What is the output of this code snippet?   def concat(*args, sep="/"): return sep.join(args) print(concat("A", "B", "C", sep=","))   String concatenation is the process of creating a string by appending string arguments. The given function takes an arbitrary number of string arguments as specified by the *args keyword. The parameter sep declares the separator string …

Arbitrary Argument Lists, String Concatenation, and the Join Function in Python Read More »