Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

list-manipulation

How to remove every occurrence of sub-list from list

May 27, 2023 by Tarik

You’d have to implement it yourself. Here is the basic idea: def remove_sublist(lst, sub): i = 0 out = [] while i < len(lst): if lst[i:i+len(sub)] == sub: i += len(sub) else: out.append(lst[i]) i += 1 return out This steps along every element of the original list and adds it to an output list if … Read more

Categories python Tags list-manipulation, python Leave a comment

Some built-in to pad a list in python

November 19, 2022 by Tarik

a += [”] * (N – len(a)) or if you don’t want to change a in place new_a = a + [”] * (N – len(a)) you can always create a subclass of list and call the method whatever you please class MyList(list): def ljust(self, n, fillvalue=””): return self + [fillvalue] * (n – len(self)) … Read more

Categories python Tags list, list-manipulation, python Leave a comment

How can I get the concatenation of two lists in Python without modifying either one? [duplicate]

September 8, 2022 by Tarik

Yes: list1 + list2. This gives a new list that is the concatenation of list1 and list2.

Categories python Tags concatenation, list-manipulation, python, sequence Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa