在python中以特殊顺序合并两个列表

时间:2019-02-02 18:37:35

标签: python list arraylist concatenation

我有这些2所列出:

char= ['aa', 'bb', 'cc']

number= [100, 200, 300]

和我想的情况如下:

result = [ ['aa',100], ['bb',200], ['cc',300] ]

谢谢

2 个答案:

答案 0 :(得分:1)

您可以使用列表中理解和拉链打造你的愿望清单。

characters = ['aa', 'bb', 'cc']
numbers = [100, 200, 300]
result = [[x, y] for x, y in zip(characters, numbers)]

答案 1 :(得分:0)

//Initialize uri lists with uploadModelClassArrayList so that they have same size
    for (int i = 0; i < 4; i++) {
            uploadModelClassArrayList.add(new UploadModelClass("123445", "Bulb"));
            imagesUris1.add("");
            imagesUris2.add("");
            imagesUris3.add("");
        }

//Pass lists to the adapter constructor
    uploadAdapter = new UploadAdapter(this, uploadModelClassArrayList, imagesUris1,
                imagesUris2, imagesUris3, UploadActivity.this);

//Initialize adapter lists
    public UploadAdapter(Context ctx, List<UploadModelClass> uploadModelClassList,
                ArrayList<String> firstImagelist, ArrayList<String> secondImagelist,
                ArrayList<String> thirdImagelist, Callback callback) {
            this.ctx = ctx;
            this.firstImageUris = firstImagelist;
            this.secondImageUris = secondImagelist;
            this.thirdImagesUris = thirdImagelist;
            this.uploadModelClassList = uploadModelClassList;
            this.mCallback = callback;
    }