Discontiguous array slices in Python -


I would like to get an array piece containing two (or more) isolated parts.

Example:

  & gt; & Gt; & Gt; A = Category (100)> gt; & Gt; & Gt; A [78:80; 85:97] # & lt; = Invalid syntax [78, 79, 85, 86]   

This syntax is not accepted. What is the best way to do this?

Update: was above the example int , but I wanted to do this mainly to work on strings like this.

Example:

  & gt; & Gt; & Gt; A = "ABCDEFG" .split ()> & gt; & Gt; & Gt; One [1: 3; 4: 6] ['B', 'C', 'E', 'F']    

What about it

  & gt; & Gt; & Gt; A = Category (100)> gt; & Gt; & Gt; One [78:80] + one [85:97] [78, 79, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96]   

Update: Make sure that you want to output as your string example:

  & gt; & Gt; & Gt; Import string & gt; & Gt; & Gt; A = list (string lowercase [: 7])> gt; & Gt; & Gt; One [1: 3] + one [4: 6] ['B', 'C', 'E', 'F']    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -