我正在尝试创建一个连接多个列表的函数,如果一个元素在2个或更多不同的列表中是相同的.
示例:
[[1,2],[3,4,5],[0,4]] 会成为 [[1,2],[0,3,4,5]
[[1],[1,2],[0,2]] 会成为 [[0,1,2]]
[[1, 2], [2, 3], [3, 4]] 会成为 [[1,2,3,4]]
事实上,如果它们有一个共同的元素,我们只是重新组合列表,我们删除这两个元素中的一个.决赛名单必须具有独特的元素.
我试着做以下功能.它可以工作,但是当使用大列表(大约100或200个列表列表)时,我得到以下递归错误:
RecursionError: maximum recursion depth exceeded while getting the repr of an object
def concat(L):
break_cond = False
print(L)
for L1 in L:
for L2 in L:
if (bool(set(L1) & set(L2)) and L1 != L2):
break_cond = True
if (break_cond):
i, j = 0, 0
while i < len(L):
while j < len(L):
if (bool(set(L[i]) & set(L[j])) and i != j):
L[i] = …Run Code Online (Sandbox Code Playgroud) 我目前正在使用Bitmap,并尝试对像素进行一些操作。我想使用Color.argb(),Color.valueOf()但是对于API Level <26而言,这些功能不起作用。
是否有任何库或类似的东西可以与任何API Level> 21一起使用?
这是我使用的部分功能:
int width = myBitmap.getWidth();
int height = myBitmap.getHeight();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
int [] allpixels = new int [ bmp.getHeight()*bmp.getWidth()];
myBitmap.getPixels(allpixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),bmp.getHeight());
bmp.setPixels(allpixels, 0, width, 0, 0, width, height);
for(int i =0; i<bmp.getHeight()*bmp.getWidth();i++) {
allpixels[i] = Color.argb(
Color.valueOf(allpixels[i]).red(),
Color.valueOf(allpixels[i]).red(),
Color.valueOf(allpixels[i]).green(),
Color.valueOf(allpixels[i]).blue());
}
Run Code Online (Sandbox Code Playgroud)