delete delete
- cofi
- Python-Forum Veteran
- Beiträge: 4432
- Registriert: Sonntag 30. März 2008, 04:16
- Wohnort: RGFybXN0YWR0
Das kann sich durchaus widersprechen.zulu321 hat geschrieben:Wäre auch praktisch wenn man irgendwie einen Einzeiler daraus machen könnte damit das Programm übersichtlich bleibt.
Einigermaßen üblich sind RegExp (und genau da widerspricht sich das in der Regel).
http://docs.python.org/library/re.html
http://docs.python.org/howto/regex.html
Michael Markert ❖ PEP 8 Übersetzung ❖ Tutorial Übersetzung (3.x) ⇒ Online-Version (Python 3.3) ❖ Deutscher Python-Insider ❖ Projekte
Code: Alles auswählen
>>> from itertools import imap
>>> def is_ipv4_address(address):
... try:
... numbers = imap(int, address.split('.'))
... except ValueError:
... return False
... else:
... return len(numbers) == 4 and all(0 <= num <= 255 for num in numbers)
Code: Alles auswählen
def is_ip4(ip):
parts = ip.split('.')
return len(parts) == 4 and all((part.isdigit() and (255 >= int(part) >=0)) for part in parts)
[url=http://wiki.python-forum.de/PEP%208%20%28%C3%9Cbersetzung%29]PEP 8[/url] - Quak!
[url=http://tutorial.pocoo.org/index.html]Tutorial in Deutsch[/url]
[url=http://tutorial.pocoo.org/index.html]Tutorial in Deutsch[/url]