여기에 이름, 주소 및 몇 가지 텍스트가 포함 된 목록이 있으며 이름 만 잡고 싶습니다. 어떻게 할 수 있습니까? 시도했지만 얻을 수 없습니다.
my_list = ['view profile for\nAli Safaei\nlocated at 1010-650 West Georgia St Vancouver', 'view profile for\nBrian M. Baird\nlocated at 103-1185 West Georgia St Vancouver', 'view profile for\nKarim A. Lalani\nlocated at 1308 Alberni St Vancouver', 'view profile for\nNishant Goswami\nlocated at 201-1743 Robson St Vancouver', 'view profile for\nEric P.J. Bussieres\nlocated at 201-1128 Hornby St Vancouver']
이름을보고 싶다면 다음으로 볼 수 있습니다.
print(my_list[0])
Output
view profile for
Ali Safaei
located at 1010-650 West Georgia St Vancouver
이 목록에서 그 이름을 어떻게 얻을 수 있습니까?
my_list = ['view profile for\nAli Safaei\nlocated at 1010-650 West Georgia St Vancouver', 'view profile for\nBrian M. Baird\nlocated at 103-1185 West Georgia St Vancouver', 'view profile for\nKarim A. Lalani\nlocated at 1308 Alberni St Vancouver', 'view profile for\nNishant Goswami\nlocated at 201-1743 Robson St Vancouver', 'view profile for\nEric P.J. Bussieres\nlocated at 201-1128 Hornby St Vancouver']
[i.splitlines()[1] for i in my_list]
산출:
['Ali Safaei', 'Brian M. Baird', 'Karim A. Lalani', 'Nishant Goswami', 'Eric P.J. Bussieres']
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다