Skip to content

Remove unnecessary list() calls before/after sorted() #9078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gallery/others/plot_repurposing_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def __init__(self, root, transforms):
self.transforms = transforms
# load all image files, sorting them to
# ensure that they are aligned
self.imgs = list(sorted(os.listdir(os.path.join(root, "PNGImages"))))
self.masks = list(sorted(os.listdir(os.path.join(root, "PedMasks"))))
self.imgs = sorted(os.listdir(os.path.join(root, "PNGImages")))
self.masks = sorted(os.listdir(os.path.join(root, "PedMasks")))

def __getitem__(self, idx):
# load images and masks
Expand Down
6 changes: 3 additions & 3 deletions torchvision/datasets/_stereo_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ def _scan_pairs(
paths_right_pattern: Optional[str] = None,
) -> list[tuple[str, Optional[str]]]:

left_paths = list(sorted(glob(paths_left_pattern)))
left_paths = sorted(glob(paths_left_pattern))

right_paths: list[Union[None, str]]
if paths_right_pattern:
right_paths = list(sorted(glob(paths_right_pattern)))
right_paths = sorted(glob(paths_right_pattern))
else:
right_paths = list(None for _ in left_paths)
right_paths = [None for _ in left_paths]

if not left_paths:
raise FileNotFoundError(f"Could not find any files matching the patterns: {paths_left_pattern}")
Expand Down
2 changes: 1 addition & 1 deletion torchvision/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(
from pycocotools.coco import COCO

self.coco = COCO(annFile)
self.ids = list(sorted(self.coco.imgs.keys()))
self.ids = sorted(self.coco.imgs.keys())

def _load_image(self, id: int) -> Image.Image:
path = self.coco.loadImgs(id)[0]["file_name"]
Expand Down
2 changes: 1 addition & 1 deletion torchvision/datasets/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
parser.feed(fh.read())
self.annotations = parser.annotations

self.ids = list(sorted(self.annotations.keys()))
self.ids = sorted(self.annotations.keys())
self.loader = loader

def __getitem__(self, index: int) -> tuple[Any, Any]:
Expand Down
6 changes: 3 additions & 3 deletions torchvision/datasets/mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ class EMNIST(MNIST):
_merged_classes = {"c", "i", "j", "k", "l", "m", "o", "p", "s", "u", "v", "w", "x", "y", "z"}
_all_classes = set(string.digits + string.ascii_letters)
classes_split_dict = {
"byclass": sorted(list(_all_classes)),
"bymerge": sorted(list(_all_classes - _merged_classes)),
"balanced": sorted(list(_all_classes - _merged_classes)),
"byclass": sorted(_all_classes),
"bymerge": sorted(_all_classes - _merged_classes),
"balanced": sorted(_all_classes - _merged_classes),
"letters": ["N/A"] + list(string.ascii_lowercase),
"digits": list(string.digits),
"mnist": list(string.digits),
Expand Down