문제

How to compare two lists or dictionaries in easy way,

eg.

assert orig_list == new_list

If I want to check two lists in python nose tests,

Is there any built-in function can let me use?

Does compare two lists is a bad practice when doing testing ?(because I've never see it)

If there is no built-in, plugin in nose, is there any handy package can do it for me.

도움이 되었습니까?

해결책

You can use assertListEqual(a, b) and assertDictEqual(a, b) from the unittest library.

다른 팁

set is used to do that between two lists/dicts!

set(orig_list) & set(new_list)

This is one way to do it. Manually checking every element for equality.

(len(a) == len(b)) and  (all(ai == bi for ai,bi in zip(a,b)))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top