我有兩個列表,如下所示,car_xy和car_id。我寫了一個示例代碼來合併兩個列表的相應元素,但沒有獲得所需的輸出。將兩個列表的相應元素合併到一個新列表中
car_xy =[(650,700),(568,231),(789,123),(968,369)]
car_id =[284,12,466,89]
#required_details merges the two lists
required_details = list(set(car_xy+car_id))
#now if i do print required_details the ouput will be a list like;
required_details = [284,12,(650,700),89,(568,231),466,(968,369),(789,123)]
#the required details adds the information in list randomly. What if i want the first elements of both the list together, like
required_details = [[284,(650,700)],[12,(568,231),[466,(789,123)],[89,(968,369)]]
任何建議將是偉大的。
'AttributeError的: '名單' 對象有沒有屬性「push''(py2.7) –
@AyushShanker啊是啊,實際上是.append()在python固定答案 – Quartal
@Quartal它給人一種類型的錯誤:只能將元組(不是'''int')連接到元組 –