Apply flake8-comprehensions to codebase
{'login': 'Skylion007', 'id': 2053727, 'node_id': 'MDQ6VXNlcjIwNTM3Mjc=', 'avatar_url': 'https://avatars.githubusercontent.com/u/2053727?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/Skylion007', 'html_url': 'https://github.com/Skylion007', 'followers_url': 'https://api.github.com/users/Skylion007/followers', 'following_url': 'https://api.github.com/users/Skylion007/following{/other_user}', 'gists_url': 'https://api.github.com/users/Skylion007/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/Skylion007/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/Skylion007/subscriptions', 'organizations_url': 'https://api.github.com/users/Skylion007/orgs', 'repos_url': 'https://api.github.com/users/Skylion007/repos', 'events_url': 'https://api.github.com/users/Skylion007/events{/privacy}', 'received_events_url': 'https://api.github.com/users/Skylion007/received_events', 'type': 'User', 'site_admin': False}
[{'id': 1935892871, 'node_id': 'MDU6TGFiZWwxOTM1ODkyODcx', 'url': 'https://api.github.com/repos/huggingface/datasets/labels/enhancement', 'name': 'enhancement', 'color': 'a2eeef', 'default': True, 'description': 'New feature or request'}]
[]
### Feature request

Apply ruff flake8 comprehension checks to codebase. 

### Motivation

This should strictly improve the performance / readability of the codebase by removing unnecessary iteration, function calls, etc. This should generate better Python bytecode which should strictly improve performance.

I already applied this fixes to PyTorch and Sympy with little issue and have opened PRs to diffusers and transformers todo this as well.

### Your contribution

Making a PR.
{'url': 'https://api.github.com/repos/huggingface/datasets/issues/5548/reactions', 'total_count': 0, '+1': 0, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}